zxing相机肖像模式和横向上的android [英] zxing camera portrait mode and landscape on android

查看:266
本文介绍了zxing相机肖像模式和横向上的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经集成zxing库在我的应用程序。现在我想,zxing相机将工作在两个模式下的风景以及在纵向模式。现在它正在只有一个模式。有人可以帮助我如何做到这一点?

I have already integrated zxing library in my application. Now i want that zxing camera will work on both mode landscape as well as on portrait mode. now it is working on one mode only. Can somebody help me out how to do this?

推荐答案

谷歌这个问题。

我已经使用zxing zxing 2.3及以下的解决方案,为我工作。

I have used zxing zxing 2.3 and below solution worked for me.

1在CameraConfigurationManager类,setDesiredCameraParameters方法添加以下的尖线code

1 In CameraConfigurationManager class, setDesiredCameraParameters Method add below code below pointed line

- > Camera.Parameters参数= camera.getParameters();

-> Camera.Parameters parameters = camera.getParameters();

 if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        camera.setDisplayOrientation(90);
 }

2在CameraManager类,getFramingRect方法替换code如下

2 In CameraManager class, getFramingRect Method replace code as below

int width = MIN_FRAME_WIDTH; int height = MIN_FRAME_HEIGHT;
if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) {
   int tmp = 7 * screenResolution.x / 8; 
   width = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : (tmp);                   
   tmp = 1 * screenResolution.y / 3;
   height = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : ((tmp) > MAX_FRAME_HEIGHT ?  MAX_FRAME_HEIGHT : (tmp));
}else{
   // Original Code
   width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, > MAX_FRAME_WIDTH);
   height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT,  MAX_FRAME_HEIGHT); 
}

3在CameraManager类,getFramingRectIn preVIEW方法代替code如下

3 In CameraManager class, getFramingRectInPreview Method replace code as below

if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) {
   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;
}else{
   // Original code commented
   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;
}

4在德$ C $钱德勒类,德code方法添加以下的尖线code

4 In DecodeHandler class, decode Method add below code below pointed line

- >结果rawResult = NULL;

-> Result rawResult = null;

 if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
        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];
        }
        data = rotatedData;
        int tmp = width;
        width = height;
        height = tmp;

  }

请找我的工作code

Please find my working code

http://www.compyutech.co.in/repo/zxing- dynamic.zip

希望这会帮助你....

Hope this will help you....

这篇关于zxing相机肖像模式和横向上的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆