Android 如何在纵向模式下使用Zxing?
目前,zxing库仅支持横向模式。对于我的应用程序,我需要在纵向模式下使用。只需查看纵向模式下使用的问题。Android 如何在纵向模式下使用Zxing?,android,Android,目前,zxing库仅支持横向模式。对于我的应用程序,我需要在纵向模式下使用。只需查看纵向模式下使用的问题。设置显示方向(int)不影响传入的字节数组的顺序PreviewCallback.onPreviewFrame(有关更多信息,请参阅JavaDoc) 这意味着您需要旋转从previewCallback返回的数据,但这是yuv数据,您需要转换为rgb数据,然后旋转它们。可以在纵向模式下扫描条形码,但需要更长的时间,因为从yuv到rgb处理数据和旋转rgb数据需要更多的时间。 因此,这里的问题是,
设置显示方向(int)
不影响传入的字节数组的顺序PreviewCallback.onPreviewFrame
(有关更多信息,请参阅JavaDoc)
这意味着您需要旋转从previewCallback返回的数据,但这是yuv数据,您需要转换为rgb数据,然后旋转它们。可以在纵向模式下扫描条形码,但需要更长的时间,因为从yuv到rgb处理数据和旋转rgb数据需要更多的时间。
因此,这里的问题是,我们如何从previewcallback获取纵向模式的yuv数据?当我们为相机参数设置setPreviewSize时,如果不支持previewsize,则会出现异常。这就是问题所在。如果相机驱动程序不支持纵向模式的previewSize(高度>宽度),则无法在纵向模式下获取yuv数据。其余的取决于您,您可以在纵向模式下扫描条形码,但这需要更长的时间,或者您必须将屏幕方向更改为横向以更快地获得结果
- setDisplayOrientation(int)需要Android 2.2
- setDisplayOrientation(int)不影响PreviewCallback.onPreviewFrame中传递的字节数组的顺序。(有关更多信息,请参阅JavaDoc)
它支持纵向和横向两种方向。这是纵向模式扫描的解决方案 首先在应用程序级别的gradle文件中声明这两行
implementation 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
implementation 'com.google.zxing:core:3.2.0'
在xml文件和按钮的Onclick侦听器中定义一个按钮,并在MainActivity java文件中编写下面的代码
在onCreate()方法之后,在MainActivity java文件中编写以下代码
然后创建一个名为CaptureActivityPortrait的类,该类扩展CaptureActivity。这个班看起来像下面
最重要的是在清单文件中声明CaptureActivityPortrait,如下所示
只需将这些代码添加到项目的AndroidManifest.xml中即可
<activity android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="sensorPortrait"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
tools:replace="android:screenOrientation" />
请检查以下内容()
将此活动添加到清单文件
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
希望这有助于将此android:screenOrientation=“Sensor肖像”添加到您的清单中
<activity android:name=".CaptureActivity"
android:screenOrientation="sensorPortrait"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
tools:replace="android:theme"/>
我想在纵向模式下使用条形码阅读器。我找到了 正如在本帖前面的评论中提到的。我想把它作为一个答案,这样就更容易为有同样问题的人找到解决方案 要在纵向模式下使用扫描仪,您需要在
AndroidManifest.xml
中添加以下活动
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="screenOrientation" />
就这样
有关更多详细信息,请参阅链接 以下是使用zxing 2.1可以做的事情。从Zing 2.2.0开始,您可以为方向设置属性,请参阅此链接。此链接已过时。此链接导致“二维码不支持unicode”问题。。。选中此项。如果您使用的是3.x.x版本,请在AndroidManifest.xml中声明方向。更多阅读请查看并@Drew在我看来这是一个不错的答案。。。OP想要一个更支持肖像的ZXing版本,而这个答案正好提供了这一点。它也帮了我同样的要求。我相信它确实帮了我。几年前,这个网站上的资源请求还可以。指导方针改变了。当新的答案带有链接的时候,你经常会收到我给你的评论,这应该是你可以接受的答案。你救了我一天。谢谢你,伙计。我从Google Vision切换到了这个,但找不到如何将默认横向方向更改为纵向的源代码。在用:compile'com.Google.zxing:core:3.2.1'更新应用程序gradle并删除清单声明中的zxing主题后,它对我也起到了作用。谢谢你!先生,你是一个英雄。绝对是一个复制和粘贴修复了我的问题。。。非常感谢你知道这对我有帮助!:)完美解决方案这是哪个版本的zxing?你救了我一个晚上,谢谢!没有人放弃投票,@rizujikeda?
package soAndSo(Your PackageName);
import com.journeyapps.barcodescanner.CaptureActivity;
public class CaptureActivityPortrait extends CaptureActivity {
}
<activity android:name=".CaptureActivityPortrait"
android:screenOrientation="sensorPortrait"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"></activity>
<activity android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="sensorPortrait"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
tools:replace="android:screenOrientation" />
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setOrientationLocked(false);
integrator.initiateScan();
<activity android:name=".CaptureActivity"
android:screenOrientation="sensorPortrait"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
tools:replace="android:theme"/>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="screenOrientation" />