• 二维码生成


    载QrCodeNet

     1 /// <summary>
     2         /// 生成QR码
     3         /// </summary>
     4         /// <param name="output_path">输出路径</param>
     5         /// <param name="text">写入文本</param>
     6         /// <param name="scale">缩放比例</param>
     7         public static void GetQRCode(String output_path, String text, Int32 scale)
     8         {
     9             QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.L);
    10             QrCode qrCode = new QrCode();
    11             qrEncoder.TryEncode(text, out qrCode);
    12 
    13             Bitmap img = new Bitmap(qrCode.Matrix.Width * scale, qrCode.Matrix.Height * scale);
    14             img.SetResolution(180f, 180f);
    15             Graphics gdiobj = Graphics.FromImage(img);
    16             gdiobj.CompositingQuality = CompositingQuality.HighQuality;
    17             gdiobj.SmoothingMode = SmoothingMode.HighQuality;
    18             gdiobj.InterpolationMode = InterpolationMode.HighQualityBicubic;
    19             gdiobj.PixelOffsetMode = PixelOffsetMode.HighQuality;
    20 
    21             for (Int32 i = 0; i < qrCode.Matrix.Height; i++)
    22             {
    23                 for (Int32 j = 0; j < qrCode.Matrix.Width; j++)
    24                 {
    25                     if (qrCode.Matrix.InternalArray[i, j])
    26                     {
    27                         gdiobj.FillRectangle(new SolidBrush(Color.Black), i * scale, j * scale, scale, scale);
    28                     }
    29                 }
    30             }
    31 
    32             System.Drawing.Imaging.EncoderParameters ep = new System.Drawing.Imaging.EncoderParameters(1);
    33             ep.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 800L);
    34 
    35             System.Drawing.Imaging.ImageCodecInfo ici = GetEncoder(ImageFormat.Png);
    36 
    37             if (ici != null)
    38             {
    39                 img.Save(output_path, ici, ep);
    40             }
    41             else
    42             {
    43                 img.Save(output_path, ImageFormat.Png);
    44             }
    45             img.Dispose();
    46             gdiobj.Dispose();
    47         }
    View Code

     比例的缩放没写好

  • 相关阅读:
    【洛谷 1144】最短路计数
    【洛谷 1608】路径统计
    【洛谷 1491】集合位置
    【洛谷 3110】驮运 Piggy Back
    【洛谷 1734】最大约束和
    【洛谷 1910】L国的战斗之间谍
    【洛谷 1048】采药
    【洛谷 1186】玛丽卡
    GeoServer(地图服务器)
    git cherry-pick 教程
  • 原文地址:https://www.cnblogs.com/chen-yu/p/3545581.html
Copyright © 2020-2023  润新知