码迷,mamicode.com
首页 > Web开发 > 详细

.net core里用ZXing生成二维码

时间:2017-08-02 18:59:21      阅读:579      评论:0      收藏:0      [点我收藏+]

标签:sharp   html   csharp   static   enc   技术分享   sla   write   获取   

先获取Nuget包

技术分享

        static void Main(string[] args)
        {
            string content = "二维码信息";
            BitMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 300, 300);
            System.Drawing.Bitmap bitmap = toBitmap(byteMatrix);
        }

        public static System.Drawing.Bitmap toBitmap(BitMatrix matrix)
        {
            int width = matrix.Width;
            int height = matrix.Height;
            var white = System.Drawing.ColorTranslator.FromHtml("0xFFFFFFFF");
            var black = System.Drawing.ColorTranslator.FromHtml("0xFF000000");
            System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    bmap.SetPixel(x, y, matrix[x, y] ? black : white);
                }
            }
            return bmap;
        }

  

 

.net core里用ZXing生成二维码

标签:sharp   html   csharp   static   enc   技术分享   sla   write   获取   

原文地址:http://www.cnblogs.com/IWings/p/7274989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!