• 大小: 26.19MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-01
  • 语言: C#
  • 标签: Afore  Zxing  二维码  C#  

资源简介

查了下,发现相关教程有,但有点模糊,也没有现成的C#winform版的源码,我就自己根据教程写了份,注释也是根据我个人理解写了许多

资源截图

代码片段和文件信息

using AForge.Video;
using AForge.Video.DirectShow;
using System;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using ZXing;

namespace 二维码扫描
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //摄像设备资源集
        private FilterInfoCollection videoDevices;
        //单个摄像设备
        private VideoCaptureDevice videoSource; 
        //开启摄像后的每次截图(拍照)
        Bitmap img;
        //扫描样式的相关参数
        int top = 0;


        private void button1_Click(object sender EventArgs e)
        {
            if (button1.Text == “开始扫描“)
            {
                button1.Text = “停止扫描“;
                //加载资源
                loadVideoSource();
                //每次截图操作
                videoSource.Newframe += new NewframeEventHandler(video_Newframe);
                //开启摄像头(此时没有展示拍摄图像)
                videoSource.Start();
                //根据每次截图的照片进行扫描图形
                timer1.Start();
                //展示并画出扫描样式
                timer2.Start();
            }else
            {
                button1.Text = “开始扫描“;
                timer1.Stop();
                //展示并画出扫描样式
                timer2.Stop();
                CloseVideoSource();
                pictureBox1.Image = null;
            }

        }

        private void video_Newframe(object sender NewframeEventArgs eventArgs)
        {
            //拍取每一帧图片
            img = (Bitmap)eventArgs.frame.Clone();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            

        }

        private void loadVideoSource()
        {
            //获取所有摄像设备资源
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            //让videoSource为第1个摄像设备
            videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            try
            {
                if (img == null)
                {
                    return;
                }
                #region 将图片转换成byte数组
                MemoryStream ms = new MemoryStream();
                img.Save(ms System.Drawing.Imaging.ImageFormat.Bmp);
                byte[] bt = ms.GetBuffer();
                ms.Close();
                #endregion
                LuminanceSource source = new RGBLuminanceSource(bt img.Width img.Height);
                BinaryBitmap bitmap = new BinaryBitmap(new ZXing.Common.HybridBinarizer(source));
                Result result;
                try
                {
                    //开始解码
                    result = new MultiFormatReader().decode(bitmap);
                }
                catch (ReaderException re)
                {
                    return;
                }
                if (result != null)
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-14 09:29  二维码扫描\
     目录           0  2018-07-14 09:27  二维码扫描\.vs\
     目录           0  2018-07-14 09:27  二维码扫描\.vs\二维码扫描\
     目录           0  2018-07-14 09:27  二维码扫描\.vs\二维码扫描\v14\
     文件       27136  2018-07-14 10:21  二维码扫描\.vs\二维码扫描\v14\.suo
     目录           0  2018-07-14 09:29  二维码扫描\packages\
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\MonoAndroid\
     文件      453632  2018-04-14 18:26  二维码扫描\packages\ZXing.Net.0.16.4\lib\MonoAndroid\zxing.monoandroid.dll
     文件     1259008  2018-04-14 18:26  二维码扫描\packages\ZXing.Net.0.16.4\lib\MonoAndroid\zxing.monoandroid.pdb
     文件      599258  2018-04-14 18:26  二维码扫描\packages\ZXing.Net.0.16.4\lib\MonoAndroid\zxing.monoandroid.xml
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\native\
     文件     1285632  2018-04-12 17:50  二维码扫描\packages\ZXing.Net.0.16.4\lib\native\zxing.pdb
     文件        1152  2018-04-12 17:50  二维码扫描\packages\ZXing.Net.0.16.4\lib\native\zxing.pri
     文件      484864  2018-04-12 17:50  二维码扫描\packages\ZXing.Net.0.16.4\lib\native\zxing.winmd
     文件      564414  2018-04-12 17:50  二维码扫描\packages\ZXing.Net.0.16.4\lib\native\zxing.xml
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20\
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20-cf\
     文件      457728  2018-04-14 18:25  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20-cf\zxing.ce2.0.dll
     文件     1236480  2018-04-14 18:25  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20-cf\zxing.ce2.0.pdb
     文件      604647  2018-04-14 18:25  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20-cf\zxing.ce2.0.xml
     文件      456704  2018-04-14 18:39  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20\zxing.dll
     文件     1261056  2018-04-14 18:39  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20\zxing.pdb
     文件      605913  2018-04-14 18:39  二维码扫描\packages\ZXing.Net.0.16.4\lib\net20\zxing.xml
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\net35\
     目录           0  2018-07-14 09:29  二维码扫描\packages\ZXing.Net.0.16.4\lib\net35-cf\
     文件      460800  2018-04-14 18:25  二维码扫描\packages\ZXing.Net.0.16.4\lib\net35-cf\zxing.ce3.5.dll
     文件     1234432  2018-04-14 18:25  二维码扫描\packages\ZXing.Net.0.16.4\lib\net35-cf\zxing.ce3.5.pdb
     文件      600225  2018-04-14 18:25  二维码扫描\packages\ZXing.Net.0.16.4\lib\net35-cf\zxing.ce3.5.xml
     文件      454656  2018-04-14 18:39  二维码扫描\packages\ZXing.Net.0.16.4\lib\net35\zxing.dll
............此处省略134个文件信息

评论

共有 条评论