设为首页 加入收藏

TOP

详细QRCode生成二维码和下载实现案例(二)
2019-09-17 19:07:39 】 浏览:55
Tags:详细 QRCode 生成 二维 下载 实现 案例
Request.Create(icoURL);
107 try 108 { 109 HttpWebResponse webReponse = (HttpWebResponse)webRequest.GetResponse(); 110 if (webReponse.StatusCode == HttpStatusCode.OK) 111 { 112 using (Stream stream = webReponse.GetResponseStream()) 113 { 114 Image img = Image.FromStream(stream); 115 logoImage = new Bitmap(img); 116 img.Dispose(); 117 } 118 } 119 } 120 catch { } 121 } 122 if (logoImage != null) 123 { 124 image = CoverImage(image, logoImage, graph); 125 logoImage.Dispose(); 126 } 127 //输出 128 System.IO.MemoryStream ms = new System.IO.MemoryStream(); 129 image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); 130 context.Response.ClearContent(); 131 context.Response.ContentType = "image/png"; 132 context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("QRCodeImg.png", System.Text.Encoding.UTF8)); 133 context.Response.BinaryWrite(ms.ToArray()); 134 context.Response.Flush(); 135 context.Response.End(); 136 image.Dispose(); 137 } 138 139 /// <summary> 140 /// 层叠图片 141 /// </summary> 142 /// <param name="original">原始图片(目前只支持正方形)</param> 143 /// <param name="image">层叠图片(目前只支持正方形)</param> 144 /// <returns>处理以后的图片</returns> 145 private Bitmap CoverImage(Bitmap original, Bitmap image, Graphics graph = null) 146 { 147 //缩放附加图片 148 int sideSLen = original.Width; 149 int sideTLen = sideSLen / 4; 150 image = ResizeImage(image, sideTLen, sideTLen); 151 152 // 获取GDI+绘图图画 153 graph = graph == null ? Graphics.FromImage(original) : graph; 154 155 // 将附加图片绘制到原始图中央 156 graph.DrawImage(image, (original.Width - sideTLen) / 2, (original.Height - sideTLen) / 2, sideTLen, sideTLen); 157 158 // 释放GDI+绘图图画内存 159 graph.Dispose(); 160 161 // 返回处理结果 162 return original; 163 } 164 165 /// <summary> 166 /// 图片缩放 167 /// </summary> 168 /// <param name="bmp">原始Bitmap</param> 169 /// <param name="newW">新的宽度</param> 170 /// <param name="newH">新的高度</param> 171 /// <returns>处理以后的图片</returns> 172 private Bitmap ResizeImage(Bitmap original, int width, int height) 173 { 174 try 175 { 176 Bitmap image = new Bitmap(width, height); 177 Graphics graph = Graphics.FromImage(image); 178 // 插值算法的质量 179 graph.CompositingQuality = CompositingQuality.HighQuality; 180 graph.SmoothingMode = SmoothingMode.HighQuality; 181 graph.InterpolationMode = InterpolationMode.HighQualityBicubic; 182 graph.DrawImage(original, new Rectangle(0, 0, width, height), 183 new Rectangle(0, 0, original.Width, original.Height), GraphicsUnit.Pixel); 184 graph.Dispose(); 185 return image; 186 } 187 catch 188 { 189 return null; 190 } 191 } 192 193 public bool IsReusable 194 { 195 get 196 { 197 return false; 198 } 199 } 200 } 201 }

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇SSRS分页 下一篇C# -Asp.Net.SignalR.Core之Hub

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目