Our Customers
|
How to read barcode with image corrections applied in C#.NET?
Using free C# code to scan linear & 2d barcode images in .NET applications
How to improve barcode recognition rate by resizing the image using C#?
If you use the barcode reader library to scan the image below, the barcode library cannot recognize the QR Code successfully.
After enlarge the above barcode image, you can find that the image quality is poor. There are many noises inside the QR Code modules, which will affect the barcode scanning result.
To recognize the barcode from the image file, you can enlarge the image width and height. The C# source code below will zoom (enlarge) the image by 2.
And the barcode reader library will return the scanned QR Code data from the enlarged image.
Bitmap bitmap = new Bitmap("D:\test.png");
Console.WriteLine(">>> Try origin Bitmap");
reportResult(BarcodeReader.ReadBarcode(bitmap, BarcodeReader.QRCODE));
Console.WriteLine(">>> Try x2 for source Bitmap");
Bitmap bitmapx2 = resizeBitmap(bitmap, 2);
reportResult(BarcodeReader.ReadBarcode(bitmapx2, BarcodeReader.QRCODE));
Console.WriteLine(">>> Try x4 for source Bitmap");
Bitmap bitmapx4 = resizeBitmap(bitmap, 4);
reportResult(BarcodeReader.ReadBarcode(bitmapx4, BarcodeReader.QRCODE));
// ...
// To zoom the source Bitmap
private static Bitmap resizeBitmap(Bitmap src, int zoomRatio)
{
Bitmap result = new Bitmap(src.Width * zoomRatio, src.Height * zoomRatio);
using (Graphics g = Graphics.FromImage(result))
{
g.DrawImage(src, 0, 0, result.Width, result.Height);
}
return result;
}
// Report the scan result
private static void reportResult(BarCode[] result)
{
if (result != null && result.Length > 0)
{
foreach (BarCode b in result)
Console.WriteLine("Message: {0}", b.GetMessage(Encoding.UTF8));
}
else
Console.WriteLine("No Barcode Found.");
Console.WriteLine();
}
Barcode reader scanning result using the above C# source code.
.NET Barcode Reader, ASP.NET Barcode Reader, C#.NET Barcode Reader, VB.NET Barcode Reader, QR Code .NET Reader, QR Code ASP.NET Reader, QR Code C# Reader, QR Code VB.NET Reader, Data Matrix .NET Reader, Code 128 .NET Reader,Code 39 .NET Reader. .NET Barcode Generator Control, ASP.NET Barcode Generator Control. |