我已成功使用ZXing条形码扫描库,但仅限于横屏模式。
我还成功将相机预览设置为纵向模式,并正确显示它(无需拉伸),但现在条形码根本不起作用。 以下是我对“CameraConfigurationManager.java”中的“setDesiredCameraParameters”所做的更改,以便正确显示相机:
I've tried some solutions mentioned on other places, but either they don't work or they work but cannot show the camera preview correctly. Examples: 如何在横屏模式下使用Zxing? http://code.google.com/p/zxing/issues/detail?id=178#c46 https://github.com/pplante/zxing-android/issues When I'm finished with that, I also need to customize the location and size of the rectangle for the scanning. I know that I need to change "setManualFramingRect" in "CameraManager.java", but I'm not sure if I'm doing it correctly. Here's the code for that:
当然,我已经修改了“openDriver”的调用方式:
我还成功将相机预览设置为纵向模式,并正确显示它(无需拉伸),但现在条形码根本不起作用。 以下是我对“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);
}
I've tried some solutions mentioned on other places, but either they don't work or they work but cannot show the camera preview correctly. Examples: 如何在横屏模式下使用Zxing? http://code.google.com/p/zxing/issues/detail?id=178#c46 https://github.com/pplante/zxing-android/issues When I'm finished with that, I also need to customize the location and size of the rectangle for the scanning. I know that I need to change "setManualFramingRect" in "CameraManager.java", but I'm not sure if I'm doing it correctly. Here's the code for that:
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);
请帮助我。
编辑:现在我发现它不能在某些设备上工作。它在开始时崩溃,如果你调试,你会看到甚至预览也无法正常工作。