Android zxing二维码扫描 扫描框适应各种分辨率

来源:互联网 发布:python strip 多个 编辑:程序博客网 时间:2024/06/05 16:48
  1. public synchronized Rect getFramingRect() {  
  2.         if (framingRect == null) {  
  3.             if (camera == null) {  
  4.                 return null;  
  5.             }  
  6.             Point screenResolution = configManager.getScreenResolution();  
  7.             if (screenResolution == null) {  
  8.                 // Called early, before init even finished  
  9.                 return null;  
  10.             }  
  11.   
  12.             // int width = findDesiredDimensionInRange(screenResolution.x,  
  13.             // MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);  
  14.             // int height = findDesiredDimensionInRange(screenResolution.y,  
  15.             // MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);  
  16.   
  17.             /* 扫描框修改 */  
  18.             DisplayMetrics metrics = context.getResources().getDisplayMetrics();  
  19.             int width = (int) (metrics.widthPixels * 0.6);  
  20.             int height = (int) (width * 0.9);  
  21.   
  22.             int leftOffset = (screenResolution.x - width) / 2;  
  23.             int topOffset = (screenResolution.y - height) / 4;  
  24.             framingRect = new Rect(leftOffset, topOffset, leftOffset + width,  
  25.                     topOffset + height);  
  26.             Log.d(TAG, "Calculated framing rect: " + framingRect);  
  27.         }  
  28.         return framingRect;  
  29.     }