C# 将string 转换为二维码图片,然后转为base64字符串编码 。

 

 

需在nuget 添加此dll

///content字符串

public static string GetQRCode(string content, int moduleSize = 9)
{


   var encoder = new QrEncoder(ErrorCorrectionLevel.M);
   QrCode qrCode = encoder.Encode(content);
   GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZoneModules.Two), Brushes.Black, Brushes.White);

   MemoryStream memoryStream = new MemoryStream();
   render.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg, memoryStream);
   byte[] arr = memoryStream.ToArray();
   string base64Str = "data:image/jpeg;base64," + Convert.ToBase64String(arr);
   return base64Str;

}

posted on 2018-10-29 10:09  Ssumer  阅读(2424)  评论(0编辑  收藏  举报

导航