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.pdfC:\Temp\Test\SConbitScan42990006.001.03-Certificate.pdfC:\Temp\Test\SConbitScan42990006.002.02-Certificate.pdf
And their corresponding PNG's
C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.pngC:\Temp\Test\QrFolder\SConbitScan42990006.001.03-Certificate.pdf.pngC:\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.pngQR 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.pngQR 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.pngQR CODE: No QR code found
File name: C:\Temp\Test\QrFolder\SConbitScan42990006.001.04-Certificate.pdf.pngQR CODE: 33KC42990006.001.04
THE PNG FILES WERE TOO BIG FOR UPLOAD I GUESS.
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,AndrewAssociate Developer
I have been investigating into this issue a bit further, and I have asked our engineering staff to take a closer look. To ensure that this issue receives attention, I have logged it in our internal tracking systems with a development ID of 227112. I have also created a private support case so that you can track this issue. This case has an ID of CAS-177722-D3N3H9 and you can access it after signing into your Infragistics account at https://ko.infragistics.com/my-account/support-activity. You can view the status of the development issue connected to this case by selecting the "Development Issues" tab when viewing this case on the web site.
Hello Andrew,
Thank for the answers.
Indeed changing the dpi settings helped, but still for some files it just give no QR code. But the exceptions are gone.
So for now it is ok, and I can accept this answer. And let's see what the engineers will find out.
Thanks again Andrew.
Best regards
Nawed
I have received an update from our engineering teams on this matter, and it appears that this issue is being caused due to the large sizes of the image files. Since the image file provided is so large, in the process of decoding it, a byte array is created and this byte array appears to be attempting to allocate more than 2 GB of memory. A limitation exists in the .NET Framework that does not support arrays that are greater than 2 GB, and so you are receiving this exception. There is not much we can do about this in the BarcodeReader's code to prevent this, as the images need to be decoded to be read.
If you are testing against a .NET Framework version equal to or higher than 4.5, and you are on a 64bit operating system, you may be able to use the "gcAllowVeryLargeObjects" element by adding the following tags to your App.config:
<configuration> <runtime> <gcAllowVeryLargeObjects enabled="true" /> </runtime></configuration>
You can read further about this feature here: https://msdn.microsoft.com/en-us/library/hh285054(v=vs.110).aspx. Note, again, though, that this feature will only work if you are on a 64 bit operating system and are targeting .NET 4.5 or higher, and so it may not be the best solution.
The other option here is to use a lower DPI setting, which would allow you to pass smaller files to the barcode reader so that this out of memory exception no longer occurs.