zoukankan      html  css  js  c++  java
  • 生成二维码,保存成图片

            /// <summary>
            /// 生成二维码,保存成图片,使用了ZXing.Net
            /// </summary>
            static byte[] GenerateQRimage(string content)
            {
                //初始化条形码格式,宽高,以及PureBarcode=true则不会留白框
                var writer = new BarcodeWriterPixelData
                {
                    Format = BarcodeFormat.CODABAR,
                    Options = new EncodingOptions { Height = 61, Width = 267, PureBarcode = true, Margin = 1 }
                };
                var pixelData = writer.Write(content);
                using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                       System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                           pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] bytes = ms.GetBuffer();
                    return bytes;
                }
            }
  • 相关阅读:
    2021年2月13
    2021年2月12
    2021年2月11
    2021年2月10
    2021年2月9
    下载优化
    20180301越努力越轻松
    2018-03-01继续完善2
    2018-03-01继续完善
    2018-02-16 GetSameTypeQuestion
  • 原文地址:https://www.cnblogs.com/s666/p/14981489.html
Copyright © 2011-2022 走看看