RSS订阅优然探索
你的位置:首页 » 技术文章 » 正文

合成两张图片,并在上打字

选择字号: 超大 标准 发布时间:2011-1-23 18:57:44 | 作者:admin | 0个评论 | 人浏览

/// <summary>
        /// 合成两张图片
        /// </summary>
        /// <param name="sourcefile">原始图案背景图</param>
        /// <param name="composefile">要合成的图案 </param>
        /// <param name="newfile">新文件名</param>
        public void view_picture(string sourcefile, string composefile, string newfile,string[] sInfo)
        {
            System.Drawing.Image imgClothing = null;
            imgClothing = System.Drawing.Image.FromFile(sourcefile);//原始图案  
            Graphics gPrimalClothing = Graphics.FromImage(imgClothing);


            System.Drawing.Image imgPic = null;
            imgPic = System.Drawing.Image.FromFile(composefile);//要合成的图案  

            //int xPosOfPic = (281 - 100 + 10) / 2;
            //int yPosOfPic = (238 - 90 - 20) / 2;

            int xPosOfPic = 23;
            int yPosOfPic = 47;
            gPrimalClothing.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            gPrimalClothing.DrawImage(
            imgPic.GetThumbnailImage(85, 85, null, IntPtr.Zero),
            new Rectangle(xPosOfPic, yPosOfPic, 85, 85),
            0, 0, 85, 85, GraphicsUnit.Pixel);//合成图案  

            #region 向上面打字

            Bitmap bmp = new Bitmap(imgClothing);
            //从Bitmap创建一个System.Drawing.Graphics对象,用来绘制高质量的缩小图。
            System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);
            //设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality
            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //下面这个也设成高质量
            gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            //下面这个设成High
            gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            SolidBrush drawBrush = new SolidBrush(ColorTranslator.FromHtml("#514E00"));
            Font drawFont = new Font("Arial", 3, FontStyle.Regular, GraphicsUnit.Millimeter);
            //Font drawFont = new Font("宋体", 4, FontStyle.Regular, GraphicsUnit.Millimeter);


            int xPos = 122;//文字X轴坐标
            int yPos = 48;  //文字Y轴坐标

            //设置好x,y坐标,可以写多个

            for (int i = 0; i < 4; i++)
            {
                gr.DrawString(sInfo[i], drawFont, drawBrush, xPos, yPos + (i*22));
            }
            //保存图像,大功告成!
            bmp.Save(newfile);
            #endregion

            Response.ContentType = "image/jpeg";
            Response.Charset = "gb-2312";
            //直接在页面输出
            //imgClothing.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            //imgClothing.Save(newfile);
            imgClothing.Dispose();
            gPrimalClothing.Dispose();
        }

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。