关闭

android zxing二维码横屏改竖屏

标签: andoridzxing二维码横屏改竖屏
917人阅读 评论(0) 收藏 举报
分类:

转载请注明出处:http://blog.csdn.net/zhouli_csdn/article/details/49930323


1.修改manifest文件,将CaptureActivity的screenOrentatino设为portrait。

2.摄像头调整为竖向在CameraConfigurationManager类中添加如下方法:

protected void setDisplayOrientation(Camera camera, int angle) {//mycode

      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();
       }      
}
在CameraConfigurationManager的setDesiredCameraParameters方法中调用此方法。

setDisplayOrientation(camera, 90);//mycode


3.CameraConfigurationManager类的initFromCameraParameters方法中注释一下代码:

//这段代码用于横屏的时候+
    /*if (width < height) {
      Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
      int temp = width;
      width = height;
      height = temp;
    }*/

4.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;*/
      
      //竖屏模式mycode
      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;
5.CameraManager类的getFramingRect方法修改:
//用于横屏时候的扫描mycode
      //int width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
      //int height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
      
      //用于竖屏的扫描
      int height = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
      int width = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);

6.DecodeHandler修改decode方法

PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);之前加入一下代码

//mycode
    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 = activity.getCameraManager().buildLuminanceSource(data, width, height);



1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    名人名言
    独学而无友孤陋寡闻也!
    个人资料
    • 访问:66778次
    • 积分:1048
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:14篇
    • 译文:4篇
    • 评论:25条