This project has moved. For the latest updates, please go here.
2
Vote

Windows phone 8 - Barcode scan is not working in Portrait orientation

description

For Windows phone 8 Barcode scan, I am using zxing 0.11.0.0. Barcode scan is not working in Portrait orientation. Is there any know issue with Windows phone 8? Pls let me know the fix

comments

fabianhenzler wrote May 28, 2013 at 5:27 AM

Dear aravinda_l,

thank you for your interest in ZXing.Net.
We did provide a new Windows Phone 8 Demo Client in the Source Code section for you. It uses many of the new Windows Phone RT features and the MVVM Pattern.
Just go to 'SOURCE CODE' and then click download on the right area. It'll provide you with the newest .

If there is anything else, just stop by :)
fäb

slavisa016 wrote Sep 10, 2013 at 8:52 AM

Hi,
I'm using 0.11.0.2 for WP8. I'm currently testing your WP8 DemoClient. My test device is Nokia Lumia 520.
I'm trying to scan barcode from camera feed.
The problem is, just like previous user asked, that I can't get it to work in portrait mode. In potrait mode camera shows ok feed, with proper orientation, but barcode can't be recognized if I put the barcode horizontally. Only when I turn barcode vertically, then it is recognized.
Please advice...
Thank you

wrote Sep 10, 2013 at 9:05 AM

fabianhenzler wrote Sep 10, 2013 at 9:25 AM

Hi,

did you try to set "_scanner.Autorotate = true"?

slavisa016 wrote Sep 10, 2013 at 9:52 AM

Hi fabianhenzeler,
I can't find that property...
My _reader don't have Autorotate property. It has "Try harder", among others, but not "Autorotate".
Thanks

slavisa016 wrote Sep 10, 2013 at 9:53 AM

Previous comment addition:
IBarcodeReader _reader

slavisa016 wrote Sep 10, 2013 at 10:14 AM

Any advice?

slavisa016 wrote Sep 10, 2013 at 11:54 AM

Anything?

fabianhenzler wrote Sep 10, 2013 at 12:23 PM

Hi,

please try
var barcodeReader = new BarcodeReader();
barcodeReader.TryHarder = true;
barcodeReader.AutoRotate = true;

poisonivy1979 wrote Mar 29 at 1:40 PM

Hi I am confused about the same error as slavisa016

what I tried is a lot of stuff including Setting all These Options in all possible combinations. But nothing worked. It seems like there is a "secretly" Rotation of my Bitmap or LuminanceSource that I cannot escape from...
            // load a bitmap
            var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
            if (lowLagCapture == null) return;
            var capturedPhoto = await lowLagCapture.CaptureAsync();
            if (capturedPhoto != null)
            {
                var croppedBitmap = GetCroppedBitmapAsync(capturedPhoto.Frame.SoftwareBitmap);
                var softwareBitmap = SoftwareBitmap.CreateCopyFromBuffer(croppedBitmap.PixelBuffer, BitmapPixelFormat.Bgra8, croppedBitmap.PixelWidth, croppedBitmap.PixelHeight);
                var source = new SoftwareBitmapSource();
                if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                        softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
                {
                    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }
                await source.SetBitmapAsync(softwareBitmap);

                imgOutput.Source = source;
                croppedBitmap = new WriteableBitmap(softwareBitmap.PixelWidth, softwareBitmap.PixelHeight);

                softwareBitmap.CopyToBuffer(croppedBitmap.PixelBuffer);
                BitmapLuminanceSource luminanceSource = new BitmapLuminanceSource(croppedBitmap);

                //detect and decode the barcode inside the bitmap
                var reader = new BarcodeReader();
                if (_mediaCapture.GetPreviewRotation().Equals((VideoRotation.Clockwise90Degrees)) || _mediaCapture.GetPreviewRotation().Equals((VideoRotation.Clockwise270Degrees)))
                {
                    //if (luminanceSource.RotateSupported)
                    //    luminanceSource.rotateCounterClockwise();
                    reader.AutoRotate = true;
                    reader.Options.TryHarder = true;
                    //reader.Options.PureBarcode = false;
                    //reader.Options.Hints.Add(DecodeHintType.TRY_HARDER_WITHOUT_ROTATION, true);
                }
                this._barcodeResult = reader.Decode(luminanceSource);

                if (this._barcodeResult != null)
                {
                    this._foundOrCancelled = true;
                    this.OnBarcodeReading(this._barcodeResult);
                }
            }
            await lowLagCapture.FinishAsync();
the softwareBitmap is just for showing on Screen what i will send to the BarcodeReader...
in the Method GetCroppedBitmapAsync I copy the softwarebitmap to a writeableBitmap, rotate it if the app is in Portrait mode and crop it a bit, whichs works pretty fine, as i can see on Screen...

So can you please please help?

micjahn wrote Mar 29 at 6:40 PM

I need a dump of the values of croppedBitmap.PixelBuffer for analyzing.

poisonivy1979 wrote Mar 30 at 6:26 AM

Hi ,

there might be a Problem with the LowLagCapture object. I have a solution which scans Barcodes properly:
            WriteableBitmap bitmap;
            SoftwareBitmap swb;
            // Find the highest resolution available
            VideoEncodingProperties resolutionMax = null;
            int max = 0;
            var resolutions = this._mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
            for (var i = 0; i < resolutions.Count; i++)
            {
                VideoEncodingProperties res = (VideoEncodingProperties)resolutions[i];

                if (res.Width * res.Height > max)
                {
                    max = (int)(res.Width * res.Height);
                    resolutionMax = res;
                }
            }
            await this._mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, resolutionMax);

            using (var captureStream = new InMemoryRandomAccessStream())
            {

                await this._mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream);
                captureStream.Seek(0);

                BitmapDecoder dec = await BitmapDecoder.CreateAsync(captureStream);
                swb = await dec.GetSoftwareBitmapAsync();

                bitmap = new WriteableBitmap(swb.PixelWidth, swb.PixelHeight);
                //bitmap.SetSource(captureStream);
                swb.CopyToBuffer(bitmap.PixelBuffer);

            }

            var croppedBitmap = GetCroppedAndRotatedBitmap(bitmap);

            BarcodeReader reader = new BarcodeReader();
            reader.AutoRotate = true;
            reader.Options.TryHarder = true;
            Result readerResult = reader.Decode(croppedBitmap);

            if (readerResult != null)

                {
                    this._foundOrCancelled = true;
                    this.OnBarcodeReading(this._barcodeResult);
                }
best regards Yvonne