Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding Barcode using Zxing library works on 1 tablet but does not work on another tablet

I have written a windows store app in XAML & C# to read image from tablet's webcam and decode the barcode using Zxing's lbrary. The code is working fine on a given tablet having an i5 processor while it fails to run on an actual tablet with 2MP camera and "Intel Baytrail Quad-Core" processor.

Any ideas on why this could happen?

Please let me know if you need to see my code for this issue ad I will share.

I am wondering how can the same code work on 1 tablet while fail on another tablet.

Thanks in advance for any help provided.

EDIT

Code used to scan the barcode and read as below - The last if/else block is what I get to. No exception raised :(

string barcodeData = string.Empty;
            using (var imageStream = new InMemoryRandomAccessStream())
            {
                processingImage = true;
                var encodingProperties = new ImageEncodingProperties();
                encodingProperties.Subtype = "Jpeg";
                encodingProperties.Width = 400;
                encodingProperties.Height = 400;

                await captureMgr.CapturePhotoToStreamAsync(encodingProperties, imageStream);
                await imageStream.FlushAsync();
                imageStream.Seek(0);

                var bitmap = new WriteableBitmap(400, 400);
                bitmap.SetSource(imageStream);
                preview1.Source = bitmap; //preview1 is an Image control to display the captured image

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(imageStream);

                imageStream.Seek(0);

                var bitmapDecoder = await BitmapDecoder.CreateAsync(BitmapDecoder.JpegDecoderId, imageStream);

                var data = await bitmapDecoder.GetPixelDataAsync(
                    BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Straight,
                    new BitmapTransform(),
                    ExifOrientationMode.IgnoreExifOrientation,
                    ColorManagementMode.DoNotColorManage
                    );
                if (data != null)
                {
                    BarcodeReader barcodeReader = new BarcodeReader();

                    var result = barcodeReader.Decode(
                        data.DetachPixelData(),
                        (int)bitmapDecoder.PixelWidth,
                        (int)bitmapDecoder.PixelHeight,
                        ZXing.RGBLuminanceSource.BitmapFormat.BGR32
                        );
                    if (result != null)
                    {
                        //Barcode found
                    }
                    else
                       //No data found.
                }
            }
like image 517
Nitesh Avatar asked Dec 10 '14 12:12

Nitesh


1 Answers

I guess you are using ZXing.NET library. Have you ever considered moving to another barcode scanner library?

Accessing the "ISSUES" section in ZXing.NET Library, you can see that there's a lot of bugs still opened for Windows Phone (and should be Window Store also).

http://zxingnet.codeplex.com/workitem/list/basic

One of it called my attention. Check out this comment:

While the WP samples all target Silverlight, you must not forget that the new WP8.1 base is WinRT - so I suggest you use the WinRT sample as a base.

I tried to do the same, but truth to be told, ZXing lacks a lot ATM for WinRT Universal Apps - it's slow, unreliable, and barely ever recognizes a thing.

http://zxingnet.codeplex.com/workitem/13311

I don't know how reliable this is, but the last time the project was updated was on April 7th!!!!

You should really consider changing you library!

like image 124
rodrigogq Avatar answered Oct 16 '22 19:10

rodrigogq