Android Zxing修改为竖屏扫描,和连续扫描问题
2014-09-25 10:43
489 查看
1.在清单配置文件当中
android:screenOrientation="landscape"修改为android:screenOrientation="portrait"
2.修改CameraManager类,在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;
3.修改CameraConfigurationManager类,在initFromCameraParameters方法中
在
Log.d(TAG, "Screen resolution: " + screenResolution);这句代码后面加入下面的代码,防止修改为竖屏之后图像拉伸的问题
// 解决竖屏后图像拉伸问题 Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; // preview size is always something like 480*320, other 320*480 if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);然后再setDesiredCameraParameters方法当中加入一句代码
setDisplayOrientation(camera, 90);//把摄像头视角旋转90度
然后再这个类里面加入上面的方法
protected void setDisplayOrientation(Camera camera, int angle) { Method downPolymorphic; try { downPolymorphic = camera.getClass().getMethod( "setDisplayOrientation", new Class[] { int.class }); if (downPolymorphic != null) downPolymorphic.invoke(camera, new Object[] { angle }); } catch (Exception e1) { e1.printStackTrace(); } }
4.修改DecodeHandler类文件,在decode(byte[] data, int width, int height)方法中
在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; // Here we are swapping, that's the difference to #11 width = height; height = tmp; data = rotatedData; PlanarYUVLuminanceSource source = CameraManager.get() .buildLuminanceSource(rotatedData, width, height);然后注释掉原来的buildLuminanceSource这行调用代码。
到这里竖屏代码就修改完成了,如果想修改扫描框的大小,可以去CameraManager这个类当中,修改这些常量就可以了
private static final int MIN_FRAME_WIDTH = 240; private static final int MIN_FRAME_HEIGHT = 240; private static final int MAX_FRAME_WIDTH = 480; private static final int MAX_FRAME_HEIGHT = 360;
====================================================================
Zxing扫描一次二维码或条形码完成之后,想要继续扫描的话,就需要重新进入这个扫描页面,很麻烦,想要实现连续扫描的话,在CaptureActivity类当中加入下面这个方法:
/** * 使Zxing能够继续扫描 */ public void continuePreview() { if (handler != null) { handler.restartPreviewAndDecode(); } }这里的handler就是CaptureActivityHandler类的实例,在合适的地方调用这个方法就可以连续的进行二维码的扫描了。
相关文章推荐
- 修改zxing连续扫描条码和二维码的怪问题
- Android使用Zxing扫描二维码过程解决三星note1竖屏后花屏问题
- Android Zxing 2.2 竖屏扫描的改写。
- android Zxing二维码扫描 竖屏切换问题的解决
- android ZXing扫描 返回崩溃问题,图像拉伸
- ZXing for Android 修改为竖屏模式
- android zxing 扫描条码,竖屏扫描
- Android 使用zxing扫描二维码横屏转竖屏
- Android zxing连续扫描
- 对Zxing修改实现二维码竖屏扫描
- Xamarin.Android-用ZXing实现二维码扫描以及连续扫描
- Android二维码扫描之SimpleZXing中文乱码问题的解决
- Android使用Zxing扫描二维码改成竖屏后,后面的预览画面出现了拉伸,扭曲的解决方法
- android--zxing扫描--Method call after release问题的解决方案
- 完美解决Android使用Zxing扫描二维码改成竖屏后,后面的预览画面出现了拉伸,扭曲的情况
- Android Zxing框架扫描解决扫描框大小,图片压缩问题
- Android Zxing 转换竖屏扫描且提高识别率的方法
- 关于zxing不能连续扫描的问题(自用)
- 解决Android使用Zxing扫描二维码改成竖屏后,后面的预览画面出现了拉伸,扭曲的情况
- zxing横屏改为竖屏识别,多次扫描,以及存在的摄像拉伸的问题