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;
        }
    
    
  • 相关阅读:
    20191003 尚硅谷Spring Cloud教学视频
    20190928 On Java8 第二十三章 注解
    C# 输出结果有System.Byte[]
    linux 命令
    用go run命令启动main package中的多个文件
    Docker使用入门
    Go实现mqtt服务
    MongoDB的Go语言驱动注意点
    Go实现发送解析GET与POST请求
    用Go实现RabbitMQ消息收发
  • 原文地址:https://www.cnblogs.com/Iven-zhang/p/10163208.html
Copyright © 2011-2022 走看看