基本信息
源码名称:C# 根据照片识别条形码
源码大小:2.81M
文件格式:.zip
开发语言:C#
更新时间:2019-06-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
根据图片识别出条形码,如果条码识别率不高,考虑是图片的DPI不够。
根据图片识别出条形码,如果条码识别率不高,考虑是图片的DPI不够。
/// <summary>
/// 条码识别
/// </summary>
privatevoidScanBarCode(stringfileName)
{
DateTime now = DateTime.Now;
Image primaryImage = Image.FromFile(fileName);
Bitmap pImg = MakeGrayscale3((Bitmap)primaryImage);
using(ZBar.ImageScanner scanner =newZBar.ImageScanner())
{
scanner.SetConfiguration(ZBar.SymbolType.None, ZBar.Config.Enable, 0);
scanner.SetConfiguration(ZBar.SymbolType.CODE39, ZBar.Config.Enable, 1);
scanner.SetConfiguration(ZBar.SymbolType.CODE128, ZBar.Config.Enable, 1);
List<ZBar.Symbol> symbols =newList<ZBar.Symbol>();
symbols = scanner.Scan((Image)pImg);
if(symbols !=null&& symbols.Count > 0)
{
stringresult =string.Empty;
symbols.ForEach(s => result ="条码内容:" s.Data " 条码质量:" s.Quality Environment.NewLine);
MessageBox.Show(result);
}
}
}
/// <summary>
/// 处理图片灰度
/// </summary>
/// <param name="original"></param>
/// <returns></returns>
publicstaticBitmap MakeGrayscale3(Bitmap original)
{
//create a blank bitmap the same size as original
Bitmap newBitmap =newBitmap(original.Width, original.Height);
//get a graphics object from the new image
Graphics g = Graphics.FromImage(newBitmap);
//create the grayscale ColorMatrix
System.Drawing.Imaging.ColorMatrix colorMatrix =newSystem.Drawing.Imaging.ColorMatrix(
newfloat[][]
{
newfloat[] {.3f, .3f, .3f, 0, 0},
newfloat[] {.59f, .59f, .59f, 0, 0},
newfloat[] {.11f, .11f, .11f, 0, 0},
newfloat[] {0, 0, 0, 1, 0},
newfloat[] {0, 0, 0, 0, 1}
});
//create some image attributes
ImageAttributes attributes =newImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(colorMatrix);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(original,newRectangle(0, 0, original.Width, original.Height),
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
//dispose the Graphics object
g.Dispose();
returnnewBitmap;
}