I participated in a competition recently and needed to implement a QR code scanning function, so I found google's open source framework Zxing, we can go to http://code.google.com/p/zxing/ to download the source code and Jar package. When I downloaded it and ran it, I found that the QR code was horizontally screened when it was recognized, and the user experience was very unpleasant, so I asked the big guys for advice on the Internet. The specific solutions are as follows:
1. In AndroidManifest.xml, modify the properties of CaptureActivity: change android:screenOrientation="landscape" to portrait
2. Find DecodeHandler.java, and modify the decode method:
Change PlanarYUVLuminanceSource source = CameraManager.get( ).buildLuminanceSource(data, width, height); Comment out and add the following code snippet:
byte[] newData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
newData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;
PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(newData, width, height);
3、找到CameraManager.java,修改其中的getFramingRectInPreview方法:
注释掉rect.left = rect.left * cameraResolution.x / screenResolution.x;
rect.right = rect.right * cameraResolution.x / screenResolution.x;
rect.top = rect.top * cameraResolution.y / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
并添加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. Find CameraConfigurationManager.java and modify the initFromCameraParameters method:
add the code at the end Point screenResolutionForCamera =new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if (screenResolution.x < screenResolution.y ) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
5. Same as the above class, modify the method setDesiredCameraParameters method:
add code at the end
// make Rotate the camera by 90 degrees
setDisplayOrientation(camera, 90);
and write a method code as follows:
/*Method to change the direction of camera imaging*/
protected void setDisplayOrientation(Camera camera, int angle) {
Method downPolymorphic = null;
try {
downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
if (downPolymorphic != null)
downPolymorphic.invoke(camera, new Object[]{angle});
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
At this point, the modification has ended, and the pro-test is valid.
Reference article: http://blog.csdn.net/chenbin520/article/details/16362459
http://407827531.iteye.com/blog/1488676
QR code scanning--transition from horizontal screen recognition to vertical screen recognition
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326270930&siteId=291194637
Recommended
Ranking