This project has moved and is read-only. For the latest updates, please go here.

WP7 Camera preview capture

Sep 19, 2012 at 10:49 PM

Hi! I moved from another port of zxing to ZXing.Net 0.8 and stopped getting any decode results of EAN 13 barcodes. I am scanning using preview Y-buffer of my camera. I downloaded the source and found the same problems running the WindowsPhoneDemo. Scanning a captured image from the same phone's media library works perfectly. Can anyone test the sample project on the latest build? I will try to compile the lib locally and debug.

Keep up the good work!


Sep 20, 2012 at 12:50 AM

I did get results with TryHarder=true. I am going to investigate if there is some rotation going on.

Sep 20, 2012 at 6:57 AM

Welcome to ZXing.Net! From which zxing port did you come from? Perhaps I have the chance to compare the results of the other port with ZXing.Net.

Good results depend on the quality of the captured image. I don't have a physical device to test the quality of the scanning results. The Windows Phone emulator doesn't support a webcam. So I'm feeling a little bit like a developer without arms. ;)
Perhaps there are other devs who can check out the Windows Phone implementation.

One solution for better results would be if you can control the autofocus of the camera for better images. But I don't know if it works for the preview buffer.

Other steps you can go are the following:

  • set BarcodeReader.PossibleFormats to a list of the barcodes you want to scan (f.e. set only BarcodeFormat.EAN13)
  • set TryHarder = true (like you have done already)
  • set AutoRotate = true
Sep 20, 2012 at 8:31 PM

Cool, thanks for the quick reply! Here are my findings using the demo:

1) With AutoRotate=true, TryHarder=false I get orientation = 90 in the metadata, and obviously a result.

2) With AutoRotate=false, TryHarder=true I get orientation = 270 with the correct result.

Since the demo (and my application) is running in portrait mode it makes sense that the preview buffer is rotated 90 degrees. This is compensated for when displaying the preview by rotating it back in the view. I made an attempt of making a copy of the GetPreviewBufferY, rotating it back and then to copy the bytes to PhotoCameraLuminanceSource.PreviewBufferY before decoding it. I was not successful as the rotated WritableBitmapEx's ToByteArray returns an array much bigger than PreviewBufferY. I am not sure what to make of this. Anyway, if using AutoRotate or TryHarder is no big performance hit I don't think this matters.

Using the other port I was having issues using ResultPoints, as they seemed to be off (although drawing a line between the points had the same orientation), do you think this is because of the orientation?

Sep 20, 2012 at 8:57 PM

It could be a problem with the orientation. I think ZXing.Net will have the same issue. I didn't try it out.

A solution for the rotation issue with better performance could be the following changes to the demo:

  • add the line
    and use the reader with AutoRotate = false and TryHarder = false.
    The rotation can be made in dependency of the value of photoCamera.Orientation.

If you do so the reader doesn't try to decode the preview buffer with the wrong orientation.

If you found some other issues or better implementations it would be great if you can post some fixes here. That would help me improving the demo app.