生成一张带有logo的二维码图片
Posted stubborn-donkey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成一张带有logo的二维码图片相关的知识,希望对你有一定的参考价值。
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的二维码图片的主要内容,如果未能解决你的问题,请参考以下文章