将多张图片和文字合成一张图片
/// <summary> /// 调用此函数后使此两种图片合并,类似相册,有个 /// 背景图,中间贴自己的目标图片 /// </summary> /// <param name="sourceImg">粘贴的源图片</param> /// <param name="destImg">粘贴的目标图片</param> public static System.Drawing.Image CombinImage(string sourceImg, string destImg, string filename, string wxImg, string text_wx) { System.Drawing.Image imgBack = System.Drawing.Image.FromFile(sourceImg); //相框图片 //System.Drawing.Image img = System.Drawing.Image.FromFile(destImg); //照片图片 //if (img == null) //{//二维码合并 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeScale = 4;//可以调节二维码的大小 qrCodeEncoder.QRCodeVersion = 8; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; //System.Drawing.Image image = qrCodeEncoder.Encode("4408810820 深圳-广州 小江"); System.Drawing.Image img = qrCodeEncoder.Encode(destImg); // } //从指定的System.Drawing.Image创建新的System.Drawing.Graphics Graphics g = Graphics.FromImage(imgBack); // g.DrawImage(imgBack, 0, 0, 148, 124); // g.DrawImage(imgBack, 0, 0, 相框宽, 相框高); //g.FillRectangle(System.Drawing.Brushes.Black, 16, 16, (int)112 + 2, ((int)73 + 2));//相片四周刷一层黑色边框 //从网络获取图片转为byte WebClient my = new WebClient(); byte[] mybyte; mybyte = my.DownloadData(wxImg); //将byte流转为图片 MemoryStream ms1 = new MemoryStream(mybyte); Image img2 = Image.FromStream(ms1); //g.DrawImage(img, 照片与相框的左边距, 照片与相框的上边距, 照片宽, 照片高); g.DrawImage(img, 185, 552, 131, 131);//写入二维码 g.DrawImage(img2, 0, 0, 131, 131);//写入图标 g.DrawString(text_wx, new Font(FontFamily.GenericMonospace, 14f), Brushes.White, new PointF(10, 20));//写入文字 GC.Collect(); //加LOGO和微信名称 //img = System.Drawing.Image.FromFile("http://www.baidu.com/img/baidu_jgylogo3.gif"); //照片图片 //g.DrawImage(imgBack, 0, 0, 148, 124); // g.DrawImage(imgBack, 0, 0, 相框宽, 相框高); //g.FillRectangle(System.Drawing.Brushes.Black, 16, 16, (int)112 + 2, ((int)73 + 2));//相片四周刷一层黑色边框 //GC.Collect(); //输出文件流 System.IO.MemoryStream ms = new System.IO.MemoryStream(); imgBack.Save(ms, System.Drawing.Imaging.ImageFormat.Png); BytToImg(ms.ToArray(), HttpContext.Current.Server.MapPath("/rcode_system/" + filename + ".png"));//保存成文件 //输出文件流 //System.Web.HttpContext.Current.Response.ClearContent(); //System.Web.HttpContext.Current.Response.ContentType = "image/png"; //System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray()); imgBack.Dispose(); return imgBack; }
转自:https://blog.csdn.net/prospertu/article/details/51393982
111111