基本信息
源码名称:根据快递单的条码图片识别单号
源码大小:0.63M
文件格式:.rar
开发语言:C#
更新时间:2019-11-03
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍


原图是:


识别结果如下:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace ReadCode
{
    public partial class RCode : Form
    {
        public RCode()
        {
            InitializeComponent();
        }


        // 读取一维码
        static string Read1(Bitmap filename)
        {
            ZXing.BarcodeReader reader = new ZXing.BarcodeReader();
            reader.Options.CharacterSet = "UTF-8";
            //  Bitmap map = new Bitmap(filename);
            ZXing.Result result = reader.Decode(filename);
            return result == null ? "" : result.Text;
        }

        //识别
        private void btnReadCode_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(@"D:\pic\1.jpg");
            int w = bmp.Width;
            int h = bmp.Height;
            textBox1.Text = Read1(Cut(bmp, w / 2, 0, w / 2, h / 2));
        }


        /// 剪裁 -- 用GDI    
        public static Bitmap Cut(Bitmap b, int StartX, int StartY, int iWidth, int iHeight)
        {
            if (b == null)
            {
                return null;
            }
            int w = b.Width;
            int h = b.Height;
            if (StartX >= w || StartY >= h)
            {
                return null;
            }
            if (StartX   iWidth > w)
            {
                iWidth = w - StartX;
            }
            if (StartY   iHeight > h)
            {
                iHeight = h - StartY;
            }
            try
            {
                Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(bmpOut);
                g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
                g.Dispose();
                return bmpOut;
            }
            catch
            {
                return null;
            }
        }
    }
}