![](/img/trans.png)
[英]Change QR Scanner orientation with ZXING in Android Studio
[英]Android Zxing change orientation to portrait
在閱讀了幾個關於這個問題的問題和帖子后,我正在嘗試旋轉Zxing顯示器。 按照說明操作后,顯示屏確實旋轉,但掃描儀的矩形沒有按照應有的位置放置(如附圖所示)。
這就是我所做的:
在CameraConfigurationManager中:
camera.setDisplayOrientation(90);
在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;
在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;
在經歷了很多掙扎之后,我發現了問題,我希望它能在將來幫助某個人。
上initFromCameraParameters
在方法CameraConfigurationManager
有一個假設,即在掃描是ALWAYS in landscape mode
,和用於其的修復時width < height
。 如果您按照問題中的步驟刪除此檢查,它可以正常工作。
謝謝您的回答!! 它確實對我有所幫助,我注意到的一件事是至少在zxing 2.1上你需要將“rotatingData”傳遞給buildLuminanceSource而不僅僅是“data”,這一行最終會像這樣:
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
希望這有助於其他人!
好吧,我在ProjectLibrary(xzing項目)上進行了一些小改動,並且能夠將方向景觀改為肖像
在setDesiredCameraParameters method of class CameraConfigurationManager
添加了
camera.setDisplayOrientation(90);
..在我原始項目的AndroidManifest.xml
文件中。 我設置了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>
至於zxing庫:2.2.0對方向變化的支持是固有的
在清單中添加/編輯以下內容:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
在致電掃描儀時設置其他財產:
IntentIntegrator integrator = new IntentIntegrator(this);
//allows portrait/landscape mode
integrator.setOrientationLocked(false);//"additional property"
integrator.initiateScan();
參考鏈接: https : //github.com/journeyapps/zxing-android-embedded#changing-the-orientation
在CameraConfigurationManager
:
camera.setDisplayOrientation(90);
在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;
在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;
在CameraConfigurationManager
:
if (width > height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; }
為清單中的CaptureActivity
更改android:screenOrientation="portrait"
。
我是條形碼掃描儀的開發人員。 是的,要使它以縱向模式掃描需要更多。 您必須“旋轉”圖像數據,並考慮設備的方向,默認方向和傳感器的方向。
條形碼掃描儀+以縱向模式掃描,您可以通過Intent與它集成,其方式與您與條形碼掃描儀集成的方式完全相同。 (但這是一個付費應用程序。)
我嘗試了其他答案中提出的各種補丁,但條形碼識別仍然不可靠。
我強烈建議在縱向模式下使用下面的存儲庫。 嘗試一下,它快速而穩定。 我在我的混合應用中使用它。
試試這個:添加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.