Android的zxing - 人像镜头preVIEW / surfaceview被拉伸/扭曲 [英] Android zxing - portrait camera preview/surfaceview is stretched/warped

查看:710
本文介绍了Android的zxing - 人像镜头preVIEW / surfaceview被拉伸/扭曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功地使用了答案这里旋转摄像头preVIEW肖像: <一href="http://$c$c.google.com/p/zxing/issues/detail?id=178#c46">http://$c$c.google.com/p/zxing/issues/detail?id=178#c46

然而preVIEW本身被拉伸/翘曲 - 高度似乎拉伸填充框(但它可能是该宽度过大的屏幕,它是被压扁,以适应)

有没有什么办法来包装的内容,而不是使之延伸到适合的surfaceview?

编辑:我整理它通过改变'findBest previewSizeValue的方法,在CameraConfigurationManager和扭转的X和Y点,这里是code(感谢肖恩·欧文为指针下方!)

 私有静态点findBest previewSizeValue(CharSequence的previewSizeValueString,
  点screenResolution){
INT bestX = 0;
INT bestY = 0;
INT差异= Integer.MAX_VALUE的;
对于(字符串previewSize:COMMA_PATTERN.split(previewSizeValueString)){

  previewSize = previewSize.trim();
  INT dimPosition = previewSize.indexOf(X);
  如果(dimPosition℃,){
    Log.w(TAG,坏preVIEW尺寸:+ previewSize);
    继续;
  }

  INT下一页末;
  INT newY;
  尝试 {
    newY =的Integer.parseInt(previewSize.substring(0,dimPosition));
    下一页末=的Integer.parseInt(previewSize.substring(dimPosition + 1));
    //原版的:
    //下一页末=的Integer.parseInt(previewSize.substring(0,dimPosition));
    // newY =的Integer.parseInt(previewSize.substring(dimPosition + 1));
  }赶上(NumberFormatException的NFE){
    Log.w(TAG,坏preVIEW尺寸:+ previewSize);
    继续;
  }

  INT newDiff = Math.abs(下一页末 -  screenResolution.x)+ Math.abs(newY  -  screenResolution.y);
  如果(newDiff == 0){
    bestX = newY;
    bestY =下一页末;
    //原版的:
    // bestX =下一页末;
    // bestY = newY;
    打破;
  }否则如果(newDiff&LT; D​​IFF){
    bestX = newY;
    bestY =下一页末;
    //原版的:
    // bestX =下一页末;
    // bestY = newY;
    差异= newDiff;
  }

}

如果(bestX大于0&安培;&安培; bestY大于0){
  返回新的点(bestX,bestY);
}
返回null;
}
 

解决方案

您必须做一个公平一点,以得到这个工作不仅仅是设置preVIEW到肖像模式。例如,你现在需要选择一个适当的preVIEW大小,它的纵向,横向不。

包装肯定是不可取的?不,你不能让包;它总是一扔整个preVIEW图像到 SurfaceView ,如果需要的话伸展。我想你可以重新实现了很多的code做不同的事情,但它是挺难的。

I have managed to use the answer here to rotate the camera preview to portrait: http://code.google.com/p/zxing/issues/detail?id=178#c46

however the preview itself is stretched/warped - the height appears to be stretching to fill the box (but it could be that the width is too large for the screen and it is being squished to fit)

Is there any way to 'wrap' the content rather than make it stretch to fit the surfaceview?

EDIT: I sorted it by altering the 'findBestPreviewSizeValue' method in the 'CameraConfigurationManager' and reversing the X and Y points (thanks to sean owen for the pointer below!), here is the code:

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

解决方案

You have to do a fair bit more to get this to work than just set the preview to portrait mode. For example, you need to choose an appropriate preview size now that it's in portrait, not landscape.

Wrapping is surely not desirable? No you can't make it wrap; it will always fling the whole preview image onto the SurfaceView, stretching if needed. I suppose you could reimplement a lot of that code to do something different, but it would be quite hard.

这篇关于Android的zxing - 人像镜头preVIEW / surfaceview被拉伸/扭曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆