[英]Android Zxing change orientation to portrait
I'm trying to rotate Zxing display after reading a few questions and posts about the issue. 在阅读了几个关于这个问题的问题和帖子后,我正在尝试旋转Zxing显示器。 After following the instructions, the display did rotate, but the rectangle of the scanner is not positioned as it should (as can be seen on the image attached). 按照说明操作后,显示屏确实旋转,但扫描仪的矩形没有按照应有的位置放置(如附图所示)。
This is what I have done: 这就是我所做的:
in CameraConfigurationManager: 在CameraConfigurationManager中:
camera.setDisplayOrientation(90);
in DecodeHandler.java 在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;
in CameraManager.java: 在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;
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
. 上initFromCameraParameters
在方法CameraConfigurationManager
有一个假设,即在扫描是ALWAYS in landscape mode
,和用于其的修复时width < height
。 If You follow the steps in the question and remove this check, it works fine. 如果您按照问题中的步骤删除此检查,它可以正常工作。
Thank you for your answer!! 谢谢您的回答!! it really helped me, one thing that I noticed is that at least on zxing 2.1 you need to pass "rotatedData" to buildLuminanceSource instead of just "data", the line end up like this: 它确实对我有所帮助,我注意到的一件事是至少在zxing 2.1上你需要将“rotatingData”传递给buildLuminanceSource而不仅仅是“data”,这一行最终会像这样:
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
Hopefully this helps someone else! 希望这有助于其他人!
Well I made a small change in ProjectLibrary (xzing project) and able to change orientation landscape to portrait 好吧,我在ProjectLibrary(xzing项目)上进行了一些小改动,并且能够将方向景观改为肖像
In setDesiredCameraParameters method of class CameraConfigurationManager
added 在setDesiredCameraParameters method of class CameraConfigurationManager
添加了
camera.setDisplayOrientation(90);
.. in my original project's AndroidManifest.xml
file. ..在我原始项目的AndroidManifest.xml
文件中。 I set screenOrientation = portrait
and Its working fine on my ICS 4.0.3 我设置了screenOrientation = portrait
,它在我的ICS 4.0.3上工作正常
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
As of zxing library:2.2.0 support for orientation change is inherent 至于zxing库:2.2.0对方向变化的支持是固有的
Add/edit the following in manifest: 在清单中添加/编辑以下内容:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
Set additional property at call to scanner : 在致电扫描仪时设置其他财产:
IntentIntegrator integrator = new IntentIntegrator(this);
//allows portrait/landscape mode
integrator.setOrientationLocked(false);//"additional property"
integrator.initiateScan();
Reference link : https://github.com/journeyapps/zxing-android-embedded#changing-the-orientation 参考链接: https : //github.com/journeyapps/zxing-android-embedded#changing-the-orientation
In CameraConfigurationManager
: 在CameraConfigurationManager
:
camera.setDisplayOrientation(90);
In DecodeHandler.java
: 在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;
In CameraManager.java
: 在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;
In CameraConfigurationManager
: 在CameraConfigurationManager
:
if (width > height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; }
Change android:screenOrientation="portrait"
for CaptureActivity
in manifest. 为清单中的CaptureActivity
更改android:screenOrientation="portrait"
。
I'm a developer of Barcode Scanner. 我是条形码扫描仪的开发人员。 Yes, it takes a lot more than this to make it scan in portrait mode. 是的,要使它以纵向模式扫描需要更多。 You have to "rotate" the image data, and account for the orientation of the device, its default orientation, and its sensor's orientation. 您必须“旋转”图像数据,并考虑设备的方向,默认方向和传感器的方向。
Barcode Scanner+ scans in portrait mode, and you can integrate with it via Intent in exactly the same way that you integrate with Barcode Scanner . 条形码扫描仪+以纵向模式扫描,您可以通过Intent与它集成,其方式与您与条形码扫描仪集成的方式完全相同。 (However it's a for-pay app.) (但这是一个付费应用程序。)
I've tried various patches, suggested in other answers, but barcode recognition remained unreliable. 我尝试了其他答案中提出的各种补丁,但条形码识别仍然不可靠。
I highly recommend using repository below in portrait mode. 我强烈建议在纵向模式下使用下面的存储库。 Try it, it's fast and stable. 尝试一下,它快速而稳定。 I used it in my hybrid app. 我在我的混合应用中使用它。
https://github.com/Dbuggerx/BarcodeScanner https://github.com/Dbuggerx/BarcodeScanner
try this : add android:screenOrientation="sensorPortrait"
试试这个:添加android:screenOrientation="sensorPortrait"
<activity android:name=".CaptureActivity"
android:screenOrientation="sensorPortrait"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
在您的库中,转到清单文件,在活动标记下更改以下行
android:screenOrientation="portrait"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.