2012-04-12 86 views
5

我已经成功使用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); 

请帮助我。


编辑:现在我发现它在某些设备上不起作用。它一开始就崩溃了,如果你进行调试,你会发现即使是预览也不能正常工作。

+1

我认为下一篇文章可以回答我的问题:http://stackoverflow.com/questions/16252791/how-to-show-zxing-camera-in-portrait-mode-android/16252917#16252917。然而,自从我测试zxing库以来有很长一段时间,我不知道它的工作效果如何。 – 2013-04-27 14:25:17

回答

2

还有比这更多的东西。例如,当相机方向与设备方向不一致时,您需要实际“旋转”相机数据(或者,如同垂直方向进行扫描)。当使用前置摄像头时,需要考虑其旋转方向相反的事实。

+0

我尝试了我已经写过的链接 - 它不起作用。你知道一个成功的人吗? – 2012-04-12 19:50:06

+0

是的,我做到了:https://play.google.com/store/apps/details?id=com.srowen.bs.android – 2012-04-12 23:52:49

+0

我的意思是,如果任何人都可以分享解决方案(无成本)。 :) – 2012-04-13 08:14:23