zxing适应各种分辨率

zxing适应各种分辨率因为zxing实现扫描二维码的界面是由自己绘制的,发现在不同分辨率上显示的效果不一样,有的根本就重叠了,然后在网上搜索了一下,发现一篇不错的文章也讲到这种问题,分享一下http://blog.csdn.net/jdsjlzx/article/details/46429043,下边是我根据这篇博客修改过的效果,根据自己的项目,确定不同的宽高之类的值就可以了publicRectgetFra

因为zxing实现扫描二维码的界面是由自己绘制的,发现在不同分辨率上显示的效果不一样,有的根本就重叠了,然后在网上搜索了一下,发现一篇不错的文章也讲到这种问题,分享一下http://blog.csdn.net/jdsjlzx/article/details/46429043,下边是我根据这篇博客修改过的效果,根据自己的项目,确定不同的宽高之类的值就可以了

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);
  }*/
  if (framingRect == null) {
    if (camera == null) {
      return null;
    }
    Point screenResolution = configManager.getScreenResolution();
    if (screenResolution == null) {
      // Called early, before init even finished
      return null;
    }

    // int width = findDesiredDimensionInRange(screenResolution.x,
    // MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
    // int height = findDesiredDimensionInRange(screenResolution.y,
    // MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);

          /* 扫描框修改 */
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = (int) (metrics.widthPixels * 0.7);
int height = (int) (width );

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

今天的文章zxing适应各种分辨率分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/11488.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注