我已设法使用此处的答案将相机预览旋转为纵向: http ://code.google.com/p/zxing/issues/detail?id=178#c46
但是预览本身被拉伸/扭曲 - 高度似乎正在拉伸以填充框(但可能是宽度对于屏幕来说太大并且它被挤压以适应)
有什么方法可以“包装”内容而不是使其拉伸以适应表面视图?
编辑:我通过更改“CameraConfigurationManager”中的“findBestPreviewSizeValue”方法并反转 X 和 Y 点(感谢 sean owen 提供下面的指针!)对其进行排序,这是代码:
private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString,
Point screenResolution) {
int bestX = 0;
int bestY = 0;
int diff = Integer.MAX_VALUE;
for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {
previewSize = previewSize.trim();
int dimPosition = previewSize.indexOf('x');
if (dimPosition < 0) {
Log.w(TAG, "Bad preview-size: " + previewSize);
continue;
}
int newX;
int newY;
try {
newY = Integer.parseInt(previewSize.substring(0, dimPosition));
newX = Integer.parseInt(previewSize.substring(dimPosition + 1));
//original:
//newX = Integer.parseInt(previewSize.substring(0, dimPosition));
//newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
} catch (NumberFormatException nfe) {
Log.w(TAG, "Bad preview-size: " + previewSize);
continue;
}
int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
if (newDiff == 0) {
bestX = newY;
bestY = newX;
//original:
//bestX = newX;
//bestY = newY;
break;
} else if (newDiff < diff) {
bestX = newY;
bestY = newX;
//original:
//bestX = newX;
//bestY = newY;
diff = newDiff;
}
}
if (bestX > 0 && bestY > 0) {
return new Point(bestX, bestY);
}
return null;
}