How to use Zxing in portrait mode?
Just check out issue for Use Zxing in portrait mode.
Getting zxing to run in portrait mode
You could follow the instruction in the link to set up ZXing in your application. If not, you could download ZXing library into your computer and add it in libs folder.
After that, you could use ZXing in your app in Portrait mode or set it in a layout
by using CompoundBarcodeView
.
Please refer my project. I am using ZXing for it. Hope this help!
Zxing Camera in Portrait mode on Android
Here's how it works.
Step 1: Add following lines to rotate data before buildLuminanceSource(..)
in decode(byte[] data, int width, int height)
DecodeHandler.java:
byte[] 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;
width = height;
height = tmp;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
Step 2: Modify getFramingRectInPreview()
.
CameraManager.java
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;
Step 3: Disable the check for Landscape Mode in initFromCameraParameters(...)
CameraConfigurationManager.java
//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
Step 4: Add following line to rotate camera insetDesiredCameraParameters(...)
CameraConfigurationManager.java
camera.setDisplayOrientation(90);
Step 5: Do not forget to set orientation of activity to portrait. I.e: manifest
Custom Camera view using ZXING in Portrait Mode. Android
You can use the BarcodeView of the Zxing Library in your own Activity. This gives you the possibility to style the scanner and control the orientation.
https://github.com/journeyapps/zxing-android-embedded/blob/master/zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeView.java
Android Zxing change orientation to portrait
After a lot of struggling, I found the problem, and I hope it will help someone in the future.
On initFromCameraParameters
method in CameraConfigurationManager
there is an assumption that the scan is ALWAYS in landscape mode
, and therefor a fix when width < height
.
If You follow the steps in the question and remove this check, it works fine.
Change QR Scanner orientation with ZXING in Android Studio
I am using
compile 'com.journeyapps:zxing-android-embedded:3.1.0@aar'
It is different version, so I don't know if this will work for you,
but this is working for me.
More about my setup, I only compile
'com.journeyapps:zxing-android-embedded:3.1.0@aar'
'com.google.zxing:core:3.0.1'
and I did not compile
'com.journeyapps:zxing-android-integration:2.0.1@aar'
First I created an activity extend from the CaptureActivity
or click this link to view the class https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c
public class CaptureActivityPortrait extends CaptureActivity {
//Nothing in side.
}
Second, add this
integrator.setCaptureActivity(CaptureActivityPortait.class);
into your integrator code.
This is how mine looks like:
CustomIntegrator integrator = new CustomIntegrator(activity);
integrator.setDesiredBarcodeFormats(CustomIntegrator.PDF_417);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setOrientationLocked(true);
integrator.setBeepEnabled(true);
integrator.setCaptureActivity(CaptureActivityPortrait.class);
integrator.initiateScan();
Finally, at the AndroidMaifest add
<activity
android:name=".custom.CaptureActivityPortrait"
android:screenOrientation="portrait" <---this is the most important line
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
Related Topics
How to Find the Data Usage on a Per-Application Basis on Android
Lollipop's Backgroundtint Has No Effect on a Button
Pass Data from Activity to Service Using an Intent
Meaning of Choreographer Messages in Logcat
Android Lollipop Change Navigation Bar Color
How to Detect User Pressing Home Key in My Activity
How to Display Inline Images from HTML in an Android Textview
Android - Java.Lang.Securityexception: Permission Denial: Starting Intent
How to Startforeground() Without Showing Notification
Remove Data from Notification Intent
Android Turn On/Off Wifi Hotspot Programmatically
How Did Google Manage to Do This? Slide Actionbar in Android Application
Creating a Button in Android Toolbar
Switching Between Android Navigation Drawer Image and Up Caret When Using Fragments
Google Map Signed API Key Errors in Android
Latest Update on Enabling and Disabling Mobile Data Programmatically