zxingfragmentlib
zxingfragmentlib copied to clipboard
zxingfragmentlib Camera in Portrait mode on Android
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.
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.?!
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 :)
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.
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
@cognacc I think I got it. Let me test it.
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:
(use weight=1 in both LinearLayout
)
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.
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.
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 ;)
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 :-)
@cognacc I came up with something, please see SampleStretchedActivity.java
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.
I have the same problem. Any solution?
Can you test with the new code?