• 大小: 977KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: C#
  • 标签: 二维码  C#  

资源简介

把字符串转换成二维码并且显示出来的一个简洁的例子。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ThoughtWorks.QRCode.Codec;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            string qrdata = textBox1.Text.Trim();

            if(string.IsNullOrWhiteSpace(qrdata))
            {
                MessageBox.Show(“请输入要生二维码的字符串“);
                return;
            }
                
           QRCodeEncoder encoder = new QRCodeEncoder();
            encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//编码方式(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字)
            encoder.QRCodeScale = 4;//大小(值越大生成的二维码图片像素越高)
            encoder.QRCodeVersion = 0;//版本(注意:设置为0主要是防止编码的字符串太长时发生错误)
            encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;//错误效验、错误更正(有4个等级)
            encoder.QRCodeBackgroundColor = Color.White;
            encoder.QRCodeForegroundColor = Color.Black;

            System.Drawing.Image image = encoder.Encode(qrdata Encoding.UTF8);
            
         
            //System.IO.Directory.CreateDirectory(absoluteSave);
            //image.Save(SaveFilePath ImageFormat.Png);
            //        image.Dispose()

            pictureBox1.Image = image;
            //image.Dispose();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-28 12:53  WindowsFormsApplication1\
     文件         187  2018-07-28 12:52  WindowsFormsApplication1\App.config
     目录           0  2018-07-28 12:52  WindowsFormsApplication1\bin\
     目录           0  2018-07-28 12:55  WindowsFormsApplication1\bin\Debug\
     文件     6209536  2017-08-07 09:51  WindowsFormsApplication1\bin\Debug\ThoughtWorks.QRCode.dll
     文件       10240  2018-07-28 13:04  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
     文件         187  2018-07-28 12:52  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe.config
     文件       24064  2018-07-28 13:04  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
     文件       22984  2018-07-28 12:52  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
     文件         187  2018-07-28 12:52  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.config
     文件         490  2012-06-06 02:06  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
     文件        1791  2018-07-28 13:04  WindowsFormsApplication1\Form1.cs
     文件        3393  2018-07-28 13:04  WindowsFormsApplication1\Form1.Designer.cs
     文件        5817  2018-07-28 13:04  WindowsFormsApplication1\Form1.resx
     目录           0  2018-07-28 12:52  WindowsFormsApplication1\obj\
     目录           0  2018-07-28 13:04  WindowsFormsApplication1\obj\Debug\
     文件         863  2018-07-28 12:52  WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7238  2018-07-28 12:56  WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2018-07-28 12:52  WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2018-07-28 12:52  WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2018-07-28 12:52  WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2018-07-28 12:52  WindowsFormsApplication1\obj\Debug\TempPE\
     文件        1176  2018-07-28 13:01  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
     文件         975  2018-07-28 13:04  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
     文件       10472  2018-07-28 13:01  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache
     文件       10240  2018-07-28 13:04  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe
     文件         180  2018-07-28 13:04  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources
     文件       24064  2018-07-28 13:04  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb
     文件         180  2018-07-28 13:01  WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources
     文件         536  2018-07-28 12:52  WindowsFormsApplication1\Program.cs
     目录           0  2018-07-28 12:52  WindowsFormsApplication1\Properties\
............此处省略8个文件信息

评论

共有 条评论