码迷,mamicode.com
首页 > 其他好文 > 详细

生成一张带有logo的二维码图片

时间:2019-10-10 11:20:26      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:global   code   array   odi   ++   isp   stream   getc   后台   

string url = 二维码内容;
            var qrcode = QRCodeTools.EncodeQrcode(url, 500, 500, Encoding.UTF8);

            // 合成活动的LOGO图片
            var hasImage = GlobalTools.GetCommonContent("TG_EVENT_LOGO_IMG", lott.WX_LOTT_TYPE_SEQ, out contentType, out contentLength, out content)//获取后台上传的logo图;
            if (hasImage)
            {
                var logo = Image.FromStream(new MemoryStream(content));
                Graphics graph = Graphics.FromImage(qrcode);
                graph.DrawImage(logo, qrcode.Width / 2.6f, qrcode.Height / 2.6f, 100, 100);
                graph.Dispose();
            }

            Image image;
            using (MemoryStream ms = new MemoryStream())
            {
  #region 压缩二进制图片质量
 EncoderParameters encoderParameters = new EncoderParameters();
                EncoderParameter encoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 50L);//修改此参数,改变生成的图片质量
                encoderParameters.Param[0] = encoderParameter;
                ImageCodecInfo[] ImageCodecInfoArray = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo jpegImageCodecInfo = null;
                for (int i = 0; i < ImageCodecInfoArray.Length; i++)
                {
                    if (ImageCodecInfoArray[i].FormatDescription.Equals("JPEG"))
                    {
                        jpegImageCodecInfo = ImageCodecInfoArray[i];
                        break;
                    }
                }
                qrcode.Save(ms, jpegImageCodecInfo, encoderParameters);
  #endregion
                byte[] buffer = new byte[ms.Length];
                ms.Seek(0, SeekOrigin.Begin);
                ms.Read(buffer, 0, buffer.Length);
                image = System.Drawing.Image.FromStream(ms);
  imgBase64 = Convert.ToBase64String(buffer);//64位二进制图片 }

 

生成一张带有logo的二维码图片

标签:global   code   array   odi   ++   isp   stream   getc   后台   

原文地址:https://www.cnblogs.com/stubborn-donkey/p/11646074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!