生成二维码,保存成图片

        /// <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;
            }
        }
原文地址:https://www.cnblogs.com/s666/p/14981489.html