Tar*_*ara 25
这是肖像模式扫描的解决方案
首先在app level gradle文件中声明这两行
implementation 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
implementation 'com.google.zxing:core:3.2.0'
Run Code Online (Sandbox Code Playgroud)
在xml文件和Onclick Listener中定义一个按钮,在MainActivity java文件中的代码下面写下代码
IntentIntegrator integrator = new IntentIntegrator(this);
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();
Run Code Online (Sandbox Code Playgroud)
在onCreate()方法之后,在MainActivity java文件中写下以下代码
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
st_scanned_result = result.getContents();
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后创建一个名为CaptureActivityPortrait的类,它扩展了CaptureActivity.该课程如下所示
package soAndSo(Your PackageName);
import com.journeyapps.barcodescanner.CaptureActivity;
public class CaptureActivityPortrait extends CaptureActivity {
}
Run Code Online (Sandbox Code Playgroud)
最重要的是在清单文件中声明您的CaptureActivityPortrait,如下所示
<activity android:name=".CaptureActivityPortrait"
android:screenOrientation="portrait"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"></activity>
Run Code Online (Sandbox Code Playgroud)
Utt*_*tam 17
只需查看纵向模式下使用Zxing的问题.
我想在纵向模式下使用条形码阅读器。我 在此线程前面的评论中找到了这里的解决方案。我以为这是一个答案,因此更容易为遇到相同问题的人找到解决方案。
要以纵向模式使用扫描仪,您需要在中添加以下活动AndroidManifest.xml。
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="screenOrientation" />
Run Code Online (Sandbox Code Playgroud)
就是这样。
请参阅链接查看更多细节。
请检查以下内容(官方文档)
将此活动添加到清单文件
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
Run Code Online (Sandbox Code Playgroud)
将积分器OrientationLocked设置为false
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setOrientationLocked(false);
integrator.initiateScan();
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
setDisplayOrientation(int)不会影响传入的字节数组的顺序PreviewCallback.onPreviewFrame.(有关其他信息,请参阅JavaDoc)
这意味着您需要从previewCallback旋转数据返回,但这是yuv数据,您需要转换为rgb数据然后旋转它们.可以在纵向模式下扫描条形码,但这需要更长的时间,因为它需要更多的时间来处理从yuv到rgb的数据并旋转rgb数据.所以这里的问题是如何从portraitcallback中获取yuv数据用于纵向模式?当我们为摄像机参数设置setPreviewSize时,如果不支持previewsize,它将获得异常.这是这个问题的问题.如果相机驱动程序不支持纵向模式(高度>宽度)的previewSize,则无法以纵向模式获取yuv数据.其余的取决于您,您可以在纵向模式下扫描条形码,但需要更长的时间,或者您必须将屏幕的方向更改为横向以更快地获得结果.
| 归档时间: |
|
| 查看次数: |
27361 次 |
| 最近记录: |