本帖最后由 lihuioooo 于 2014-08-12 11:58:30 编辑

解决方案 »

  1.   

    调用他的代码
      private Image CreateImage()
            {
                Image img2 = null;
                object o = this.Tag;
                Seal.BLL.DynamicImage bllimm = new Seal.BLL.DynamicImage();
                List<Seal.Model.DynamicImage> modelimglist = new List<Seal.Model.DynamicImage>();
                if (o == null)
                {
                    return img2;
                }
                modelimglist = bllimm.GetModelForSealID(int.Parse(o.ToString()));
                Seal.BLL.SealInfo bllSealInfo = new Seal.BLL.SealInfo();
                Seal.Model.SealInfo modelSeal = bllSealInfo.GetModel(int.Parse(o.ToString()));
                Bitmap bit = null;
                Image img = CustomControls.ImageFormat.ReturnPhoto(modelSeal.SealImage);
                bit = new Bitmap(img);
                Graphics g = Graphics.FromImage(bit);
                //设置高质量插值法
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                //设置高质量呈现平滑程度
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //清空画布并以透明背景色填充
                g.Clear(System.Drawing.Color.Transparent);
                g.DrawImage(img, new Point(0, 0));            foreach (Seal.Model.DynamicImage item in modelimglist)
                {
                    int xpoint = int.Parse(item.SealPoint.Substring(0, item.SealPoint.LastIndexOf(",")));
                    int ypoint = int.Parse(item.SealPoint.Substring(item.SealPoint.LastIndexOf(",") + 1));
                    if (xpoint < 0)
                    {
                        xpoint = 0;
                    } if (ypoint < 0)
                    {
                        ypoint = 0;
                    }
                    Rectangle r = new Rectangle(xpoint, ypoint, (int)item.SealWidth, (int)item.SealHeight);
                    if (item.SealFontSize != null)
                    {
                        Font f = new Font(item.SealFont, (float)item.SealFontSize);
                        if (item.IsUp == false && item.Angle != null)
                        {
                            Point centerPoint = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);
                            PaintOneText(g, f, centerPoint, (float)r.X, (float)r.Y, (float)item.Angle, (float)item.TopMargin, DateTime.Now.ToString("yyyy.MM.dd"), item.IsUp, (float)r.Height, (float)r.Width);
                        }
                        else
                        {                        Random ran = new Random();
                            int temp = ran.Next(10000000, 99999999);
                            StringFormat format = new StringFormat();
                            format.Alignment = StringAlignment.Center;
                            g.DrawString(temp.ToString(), f, Brushes.Black, r, format);
                        }                }
                    if (item.LineWidth > 0)
                    {
                        int num = (int)item.LineStyle;
                        g.DrawRectangle(new Pen(Brushes.Black, (int)item.LineWidth), r);
                    }
                }
                return ImageFormat.toBitmap(bit, 160);
            }
      

  2.   

    图像是非托管资源,没看到你在任何地方调用dispose方法,是否内存溢出了?