zoukankan      html  css  js  c++  java
  • 二维码生成

    载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

     比例的缩放没写好

  • 相关阅读:
    gerrit权限控制
    kvm虚拟机根目录磁盘扩容
    vim新手指南
    精通 vim 你应该理解的几个名词
    精通 VIM ,此文就够了
    linux下库的使用--动态库
    linux下库的使用--静态库
    linux下程序编译的各个阶段记录
    ASCII码表
    重构的过程记录--之利用系统数据库:
  • 原文地址:https://www.cnblogs.com/chen-yu/p/3545581.html
Copyright © 2011-2022 走看看