82103253 2013-05-14
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源码,并验证有效可行。