Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1280
Infragistics BarcodeReder strange behaviour.
posted

Hi there,

I am using Infragistics BarcodeReader to process some documents. But the BarcodeReader behaves quite strange.

While it is scanning the same file, sometimes it give a barcode. Sometimes it doesn't.And sometimes it just throws exceptions ('System.OutOfMemoryException',  System.Runtime.InteropServices.COMException).

What I basically do is to convert some PDF's to PNG and let the Infragistics BarcodeReader decode the QR code, and I have tested with the following 3 files.

C:\Temp\Test\SConbitScan42990006.001.04-Certificate.pdf
C:\Temp\Test\SConbitScan42990006.001.03-Certificate.pdf
C:\Temp\Test\SConbitScan42990006.002.02-Certificate.pdf

And their corresponding PNG's

C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.png
C:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.png
C:\Temp\Test\QrFolder\SConbitScan42990006.002.02-Certificate.pdf.png

All files are included in the sample.

Main parts of the code:

        private static void ReadQrCode(string fileName)
        {
            var barcodeReader = new BarcodeReader();
            barcodeReader.DecodeComplete += BarcodeReader_DecodeComplete;
            var image = new BitmapImage(new Uri(fileName, UriKind.Relative));

            //Decoding an image.
            try
            {
                Console.WriteLine($"File name: {fileName}");
                barcodeReader.Decode(image);
            }
            catch (Exception e)
            {
                ...
            }
            finally
            {
                image = null;
                barcodeReader = null;
                GC.Collect();
            }
        }

        private static void BarcodeReader_DecodeComplete(object sender, ReaderDecodeArgs e)
        {
            var text = e.SymbolFound ? e.Value : "No QR code found";
           
            Console.WriteLine($"QR CODE: { text}\n ======== ");
        }

And the outputs in CONSOLE:

Exception of type 'System.OutOfMemoryException' was thrown. System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.    at Infragistics.Controls.Barcodes.ImageProcessing.ConvertGrayScaleToRgb(Array pixels, Boolean hasAlpha)    at Infragistics.Controls.Barcodes.ImageProcessing.CreateImageFromPixelsArray(Byte[][] data, ImageData imageData, Boolean isImageZoomed)    at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap, Symbology symbologyTypes)    at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap)    at InfraBarcodeScannerConsole.Program.ReadQrCode(String fileName) in C:\Users\nawed\Desktop\WorkSpaceVS\TestApplication\InfraBarcodeScannerConsole\Program.cs:line 110

Insufficient memory to continue the execution of the program. System.OutOfMemoryException: Insufficient memory to continue the execution of the program.    at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)    at Infragistics.Controls.Barcodes.ImageProcessing.CreateImageFromPixelsArray(Byte[][] data, ImageData imageData, Boolean isImageZoomed)    at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap, Symbology symbologyTypes)    at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap)    at InfraBarcodeScannerConsole.Program.ReadQrCode(String fileName) in C:\Users\nawed\Desktop\WorkSpaceVS\TestApplication\InfraBarcodeScannerConsole\Program.cs:line 110

MILERR_WIN32ERROR (Exception from HRESULT: 0x88980003) System.Runtime.InteropServices.COMException (0x88980003): MILERR_WIN32ERROR (Exception from HRESULT: 0x88980003)    at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)    at Infragistics.Controls.Barcodes.ImageProcessing.CreateImageFromPixelsArray(Byte[][] data, ImageData imageData, Boolean isImageZoomed)    at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap, Symbology symbologyTypes)    at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap)    at DCMConsoleApplication.Program.ReadQrCode(String fileName) in C:\Users\nawed\Desktop\WorkSpaceVS\TestApplication\InfraBarcodeScannerConsole\Program.cs:line 110

File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.png
QR CODE: 33KC42990006.001.04
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.png
QR CODE: 33KC42990006.001.04
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.png
QR CODE: No QR code found
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.png
QR CODE: 33KC42990006.001.04

 ========

File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.png
QR CODE: No QR code found
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.png
QR CODE: 33KC63490101.014.01
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.png
QR CODE: 33KC63490101.014.01
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.png
QR CODE: 33KC63490101.014.01

 ========

File name: C:\Temp\Test\QrFolder\SConbitScan42990006.002.02-Certificate.pdf.png
QR CODE: No QR code found
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.002.02-Certificate.pdf.png
QR CODE: 33KC63490101.014.01
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.002.02-Certificate.pdf.png
QR CODE: No QR code found
 ========
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.002.02-Certificate.pdf.png
QR CODE: 33KC63490101.014.01

 ========

File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.png
QR CODE: No QR code found

 ========

File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.png
QR CODE: 33KC42990006.001.04

 ========

THE PNG FILES WERE TOO BIG FOR UPLOAD I GUESS.

InfraBarcode.rar
Parents
No Data
Reply
  • 34830
    Offline posted

    Hello Nawed,

    I have been investigating into this issue, and I have reproduced the exceptions that you are referring to, both with the sample project you have provided me and with an external sample project that attempts to read the barcodes on button click. It appears that the COM Exception that you are currently seeing has an Out Of Memory exception occurring at its root as well, so most of the exceptions you are currently seeing are related to Out Of Memory exceptions.

    I believe this may be related to the dpi settings that you are setting on the Inkscape .png file that you are creating. I don't know much about the Inkscape command that you are passing to your ProcessStartInfo, personally, but currently it appears that you have the dpi set to 600, which is resulting in image files that are nearly 7MB on my end. I have been experimenting with your sample project in order to see if this happens with lower dpi scales, and so far, I have tested against 200 and 100 dpi scales, which lowers the size of the images significantly, and I am no longer seeing the exceptions that were occurring on your end with these dpi scales.

    It is likely that this is being caused by the sizes of the images, but that doesn't explain why the BarcodeReader seems to read the images fine sometimes, but not others. I am going to look into this a little further with our development teams to see if there is more of an underlying explanation to this, and I hope to have more information for you soon.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

Children