I've successfully modified ZXing lib to portrait mode following this post, also modify the preview rect to an square like img below. But I found the actually scanning rect is only half size of preview rect, only when I aligned qrcode to upper half of preview rect then I can get a result quick and smooth, just like ZXing demo app.
I check both getFramingRect() & getFramingRectInPreview() method in CameraManager to modify the preview rect, and from ViewFinderView.onDraw() I can print out those 2 rect. But I still don't know which rect is actually for DETECTING. Is it frame or previewFrame? Or something else? How could I align my preview square rect to the detecting rect???
@Override
public void onDraw(Canvas canvas) {
if (cameraManager == null) {
return; // not ready yet, early draw before done configuring
}
Rect frame = cameraManager.getFramingRect();
Rect previewFrame = cameraManager.getFramingRectInPreview();
if (frame == null || previewFrame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
Log.d(TAG, "@ FramingRect : " + frame.left + "/" + frame.top + "/" + frame.right + "/" + frame.bottom);
Log.d(TAG, "@ Preview FramingRect : " +
previewFrame.left + "/" + previewFrame.top + "/" + previewFrame.right + "/" + previewFrame.bottom);
Whenever I adjust the previewRect in the getFramingRectInPreview()
this exception will occur:
java.lang.IllegalArgumentException: Crop rectangle does not fit within image data.
at com.google.zxing.PlanarYUVLuminanceSource.<init>(PlanarYUVLuminanceSource.java:50)
at com.google.zxing.client.android.camera.CameraManager.buildLuminanceSource(CameraManager.java:339)
at com.google.zxing.client.android.DecodeHandler.decode(DecodeHandler.java:87)
at com.google.zxing.client.android.DecodeHandler.handleMessage(DecodeHandler.java:55)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at com.google.zxing.client.android.DecodeThread.run(DecodeThread.java:104)
After try&error I can only move previewRect down by 100, move right by 60. It seems make detecting process more smooth.