zxingfragmentlib icon indicating copy to clipboard operation
zxingfragmentlib copied to clipboard

zxingfragmentlib Camera in Portrait mode on Android

Open sanujanrozzi opened this issue 11 years ago • 13 comments

Hi friends,

I found a bug in the zxing scanner. I use zxingfragmentlib to implement my fragment scanner. I have set android:screenOrientation to "portrait" in AndroidManifest, so I can only use it in portrait orientation.

I have tested the scanner in many android devices. I´ve found out that when I use the devise where the camera width is bigger than height then it rotates the camera view to 90 dregge.

Right now I have to rotate my device to 90 dregge in order to scan the barcode. It is not a good idea to do it that way.

I google the probleme for finding a solution. I found this page: http://stackoverflow.com/questions/16252791/zxing-camera-in-portrait-mode-on-android

When I do what the Roylee says, the camera returns to the correct position but the scanner can't scan.

What should I do?

Please help me to figure out my problem I thank you in advance.

sanujanrozzi avatar Feb 12 '14 13:02 sanujanrozzi

We cannot stop the camera from rotating the image, when the camera rotates the image the scanner doenst work.

We tried modifying the isPortrait method, returning true in the else statement. Seems that is portrait, is never called. We need help resolving this issue.

For example by disabling the camera rotation.?!

cognacc avatar Mar 19 '14 17:03 cognacc

Hi!

Sorry for the delay but work has been keeping me busy.

I can't seem to replicate your problem, I've tried with an Xperia X8, Xperia Pro and Moto X, and it works fine when I scan barcodes even when forcing portrait mode.

What devices are you using?

Could you please describe your problem with more detail? Perhaps I didn't understand what you are trying to achieve.

As soon as I have more info I'll be glad to help :)

mitoyarzun avatar Mar 27 '14 20:03 mitoyarzun

Hi sorry for the delay ;)

We have two fragments for the scanner screen one part of the screen for scan information

  • scan button, the second part of the screen if the camera / scan view, where you can see the object being scanned.

We found out that when the scan screen height gets smaller than the width, then it rotates the viewed object 90 degrees and no scan will take place when you activate it.

We have tried the scanner on the following phones: Samsung Galaxy III, IV and HTC One.

Look at the picture we attached.
2014-04-03 19 20 25

cognacc avatar Apr 03 '14 19:04 cognacc

Hi! I have one problem with this library. If i put the scan view in portrait but half of height of the screen the scan view rotates and doesn´t works nice. Any solution please? Thank you

Igordroid avatar Apr 07 '14 14:04 Igordroid

@cognacc I think I got it. Let me test it.

mitoyarzun avatar Apr 07 '14 14:04 mitoyarzun

I looked into it and found a possible solution, but it needs some work.

The thing is that the camera resolution is probably not going to be proportional to the fragment's dimensions, so a workaround is to set a RelativeLayout and put the scanner behind the extra data.

Something like this:

screenshot 2014-04-07 18 22 34

(use weight=1 in both LinearLayout)

screenshot 2014-04-07 18 21 44

After that it should work well, but the problem now is the framing rectangle, which should be cut in half in this scenario.

I'll try to add an option to set custom rectangle positions, but I think it's a bit tricky so don't expect it right away. I could use some help here, so if you start playing with ``getFramingRect` methods in CameraManager.java you could get to something.

mitoyarzun avatar Apr 07 '14 21:04 mitoyarzun

Hi! How can I pause the scan without removing the camera preview? because if I use stopScan() of BarcodeScannerFragment the preview turns black. Thank you so much.

Igordroid avatar Apr 08 '14 07:04 Igordroid

Answered by e-mail, basically you should use cameraManager.stopPreview() and cameraManager.startPreview() to unbind the decoder, and stopScan() and startScan() to re bind it.

Please feel free to open another issue for future questions, that way we can keep threads clean ;)

mitoyarzun avatar Apr 08 '14 15:04 mitoyarzun

Hi! Thank you for the answer but I am not able. I am trying to use this from SampleFragment. I define CameraManager cameraManager; and later I use cameraManager.stopPreview(), is like this? Thank you, I am novice :-)

Igordroid avatar Apr 08 '14 15:04 Igordroid

@cognacc I came up with something, please see SampleStretchedActivity.java

mitoyarzun avatar Apr 08 '14 17:04 mitoyarzun

I got a following error for my code as given below. Please help to leave from this error: I'm using Nested Fragment...

05-11 20:08:15.906: E/AndroidRuntime(2232): FATAL EXCEPTION: Thread-12823 05-11 20:08:15.906: E/AndroidRuntime(2232): java.lang.IllegalArgumentException: Crop rectangle does not fit within image data. 05-11 20:08:15.906: E/AndroidRuntime(2232): at com.google.zxing.PlanarYUVLuminanceSource.(PlanarYUVLuminanceSource.java:50) 05-11 20:08:15.906: E/AndroidRuntime(2232): at com.welcu.android.zxingfragmentlib.camera.CameraManager.buildLuminanceSource(CameraManager.java:360) 05-11 20:08:15.906: E/AndroidRuntime(2232): at com.welcu.android.zxingfragmentlib.DecodeHandler.decode(DecodeHandler.java:77) 05-11 20:08:15.906: E/AndroidRuntime(2232): at com.welcu.android.zxingfragmentlib.DecodeHandler.handleMessage(DecodeHandler.java:56) 05-11 20:08:15.906: E/AndroidRuntime(2232): at android.os.Handler.dispatchMessage(Handler.java:99) 05-11 20:08:15.906: E/AndroidRuntime(2232): at android.os.Looper.loop(Looper.java:176) 05-11 20:08:15.906: E/AndroidRuntime(2232): at com.welcu.android.zxingfragmentlib.DecodeThread.run(DecodeThread.java:101)

neruja avatar May 11 '14 18:05 neruja

I have the same problem. Any solution?

woutergoossens avatar Jun 20 '14 07:06 woutergoossens

Can you test with the new code?

mitoyarzun avatar Aug 25 '14 00:08 mitoyarzun