我已经成功使用ZXing条码扫描库,但只能在横向模式下使用。android + ZXing条码扫描库 - 自定义尺寸和方向
我也成功地将相机预览设置为肖像模式,并正确显示(没有拉伸),但现在条形码根本不起作用。 我这里还有我在为了显示正确的相机上的“CameraConfigurationManager.java”“setDesiredCameraParameters”所做的更改:
void setDesiredCameraParameters(Camera camera)
{
Camera.Parameters parameters = camera.getParameters();
Log.d(TAG, "Setting preview size: " + cameraResolution);
setFlash(parameters);
setZoom(parameters);
camera.setDisplayOrientation(90);
parameters.set("rotation", 90);
parameters.setPreviewSize(cameraResolution.y, cameraResolution.x);
camera.setParameters(parameters);
}
我已经尝试过在其他地方提到了一些解决方案,但他们要么别没有工作,或他们工作,但无法正确显示相机预览。 例子: How to use Zxing in portrait mode? http://code.google.com/p/zxing/issues/detail?id=178#c46 https://github.com/pplante/zxing-android/issues
当我完成了这一点,我还需要自定义矩形的位置&尺寸的扫描。我知道我需要更改“CameraManager.java”上的“setManualFramingRect”,但我不确定是否正确。这里是该代码:
public void setManualFramingRect(Rect rect)
{
if (initialized)
{
Point screenResolution = configManager.getScreenResolution();
if (rect.right >= screenResolution.x)
rect.right = screenResolution.x - 1;
if (rect.left < 0)
rect.left = 0;
if (rect.bottom >= screenResolution.y)
rect.bottom = screenResolution.y - 1;
if (rect.top < 0)
rect.top = 0;
framingRect = rect;
Log.d(TAG, "Calculated manual framing rect: " + framingRect);
framingRectInPreview = null;
}
else
_requestedFramingRect = new Rect(rect);
}
当然
,我已经改变了 “openDriver” 来称呼:
if (_requestedFramingRect != null)
setManualFramingRect(_requestedFramingRect);
请帮助我。
编辑:现在我发现它在某些设备上不起作用。它一开始就崩溃了,如果你进行调试,你会发现即使是预览也不能正常工作。
我认为下一篇文章可以回答我的问题:http://stackoverflow.com/questions/16252791/how-to-show-zxing-camera-in-portrait-mode-android/16252917#16252917。然而,自从我测试zxing库以来有很长一段时间,我不知道它的工作效果如何。 – 2013-04-27 14:25:17