Android Zxing調整掃描地區 最佳化取圖速度

來源:互聯網
上載者:User

標籤:二維碼   最佳化   android   zxing   取圖   

Zxing 是google提供的二維碼掃描工程

Demo本身預設的掃圖地區最大隻有 360*480    需要拉開很遠的距離才能將整個二維碼掃描到

因此需要我們自己調整取圖大小

 

在CameraManager.java這個類中進行調整

預設的大小是 以下這4個參數 

//  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;


根據螢幕大小調整      大家可以增大這些數值 : 最小的寬 高    ; 最大寬高

 

參數實際在 getFramingRect() 方法中起作用

以下是原本Demo中提供的

 /**   * Calculates the framing rect which the UI should draw to show the user where to place the   * barcode. This target helps with alignment as well as forces the user to hold the device   * far enough away to ensure the image will be in focus.   *   * @return The rectangle to draw on screen in window coordinates.   */  public Rect getFramingRect() {    Point screenResolution = configManager.getScreenResolution();    if (framingRect == null) {      if (camera == null) {        return null;      }            //原生      int width = screenResolution.x * 3 / 4;      if (width < MIN_FRAME_WIDTH) {        width = MIN_FRAME_WIDTH;      } else if (width > MAX_FRAME_WIDTH) {        width = MAX_FRAME_WIDTH;      }      int height = screenResolution.y * 3 / 4;      if (height < MIN_FRAME_HEIGHT) {        height = MIN_FRAME_HEIGHT;      } else if (height > MAX_FRAME_HEIGHT) {        height = MAX_FRAME_HEIGHT;      }      int leftOffset = (screenResolution.x - width) / 2;      int topOffset = (screenResolution.y - height) / 2;      framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);      Log.d(TAG, "Calculated framing rect: " + framingRect);    }    return framingRect;  }

 

我為了適配不同的螢幕大小將代碼改成了

  public Rect getFramingRect() {    Point screenResolution = configManager.getScreenResolution();    if (framingRect == null) {      if (camera == null) {        return null;      }          //修改之後      int width = screenResolution.x * 7 / 10;    int height = screenResolution.y * 7 / 10;        int leftOffset = (screenResolution.x - width) / 2;    int topOffset = (screenResolution.y - height) / 3;    framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);                  Log.d(TAG, "Calculated framing rect: " + framingRect);    }    return framingRect;  }

寬高 我佔據了螢幕的   7/10
當然...取圖改的這麼大   會多佔一點記憶體....相應的掃描的時候快得多

 

以上是實際讀取圖片的大小

實際的介面美化 在ViewfinderView 這個類當中進行繪製

 

不足之處請在下方留言  謝謝

希望對您有用

資源:http://download.csdn.net/detail/aaawqqq/7281577

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.