Currently zxing library supports only on landscape mode.For my app i need to use in portrait mode
Just check out issue for Use Zxing in portrait mode.
In order to make screen work in portrait, set portrait orientation for the activity (e.g. in manifest) and then config the camera: Use camera.setDisplayOrientation(90) in CameraConfigurationManager.setDesiredCameraParameters(Camera camera). But be aware that:
Because preview frames are always in "landscape", we need to rotate them. I used clockwise rotation offered by comment #11. Do not forget to swap width and height parameters after rotation. DecodeHandler.java, rotate data before buildLuminanceSource in decode(byte[] data, int width, int height)
rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width; // Here we are swapping, that's the difference to #11
width = height;
height = tmp;
I also modified CameraManager.java, getFramingRectInPreview(), as recommended by #c11:
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
I did not modify getCameraResolution(). That's the second difference to #c11.
As a result, I've got UPC and other 1D codes scanning work in portrait.
P.S. Also you may adjust the size of FramingRect (that's the rectangle visible on the screen during scanning), and FramingRectInPreview will be adjusted automatically.
add this android:screenOrientation="sensorPortrait" to your manifest
<activity android:name=".CaptureActivity"
android:screenOrientation="sensorPortrait"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
tools:replace="android:theme"/>