在使用zxing二维码时,发现有时候出现拉伸的现象,不能很好的适应各种分辨率,经过测试,只要在
CameraManager.java中,修改一下如下方法即可,代码如下:
(如果您觉得有用,欢迎加入,一起学习进步)
public synchronized Rect getFramingRect() {
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.6);
int height = (int) (width * 0.9);
int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 4;
framingRect = new Rect(leftOffset, topOffset, leftOffset + width,
topOffset + height);
Log.d(TAG, "Calculated framing rect: " + framingRect);
}
return framingRect;
}
转自:http://blog.csdn.net/jdsjlzx/article/details/46429043