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

    把链接生成二维码,代码如下:

      public void ResImg()
        {
            string contents = "http://www.baidu.com";
            Bitmap bmp = GeneratorQrImage(contents);
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] arr = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(arr, 0, (int)ms.Length);
            ms.Close();
            Response.Clear();
            Response.ContentType = "image/gif";
            Response.OutputStream.Write(arr, 0, arr.Length);
            Response.End();
        }

    /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="contents">要生成二维码包含的信息</param>
        /// <param name="width">生成的二维码宽度(默认300像素)</param>
        /// <param name="height">生成的二维码高度(默认300像素)</param>
        /// <returns>二维码图片</returns>
        public static Bitmap GeneratorQrImage(string contents, int width = 300, int height = 300)
        {
            if (string.IsNullOrEmpty(contents))
            {
                return null;
            }
            EncodingOptions options = null;
            BarcodeWriter writer = null;
            options = new QrCodeEncodingOptions
            {
                DisableECI = true,
                CharacterSet = "UTF-8",
                Width = width,
                Height = height,
                ErrorCorrection = ErrorCorrectionLevel.H,
            };
            writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            writer.Options = options;
    
            Bitmap bitmap = writer.Write(contents);
            return bitmap;
        }
    
    
  • 相关阅读:
    Apache安装与属性配置
    Web服务及http协议
    转-httpd 2.4.4 + mysql-5.5.28 + php-5.4.13编译安装过程
    LAMP理论整理
    Rhel6-csync配置文档
    转载Eclipse中Maven WEB工程tomcat项目添加调试
    转载--eclipse git插件安装
    l连接远程桌面
    Aphache VFS
    JMS-activeMQ
  • 原文地址:https://www.cnblogs.com/Iven-zhang/p/10163208.html
Copyright © 2011-2022 走看看