Android(安卓)zxing change orientation to portrait
16lz
2021-12-04
zxing https://code.google.com/p/zxing/
Multi-format 1D/2D barcode image processing library with clients for Android, Java
zxing-client-android屏幕方向默认是landscape模式,修改如下源码,可改为portrait模式:
1、AndroidManifest.xml:
将android:screenOrientation="landscape"改为
android:screenOrientation="portrait"
2、DecodeHandler.java:
在buildLuminanceSource方法调用前增加
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; data = rotatedData;
3、CameraManager.java
将已有的计算rect.left/right/top/bottom的代码,替换为
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;
4、CameraConfigurationManager.java
4.1、在setDesiredCameraParameters方法内新增代码
camera.setDisplayOrientation(90);
4.2、在initFromCameraParameters方法内注解掉代码 (最新代码可能不需要再改动此处 20130907)
/*if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; }*/
注,以上改动基于GoogleCode上最新zxing-client-android源码,并验证有效可行。
更多相关文章
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用
- python list.sort()根据多个关键字排序的方法实现
- Android发送短信方法实例详解
- android 单选框
- Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
- Android中的dispatchTouchEvent()、onInterceptTouchEvent()和on
- How To Open An URL In Android’s Web Browser
- Android也有beacon了