Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android + ZXing barcode scanning library - custom size & orientation [duplicate]

i've succeeded using the ZXing barcode scanning library , but only on landscape mode.

i've also succeeded setting the camera preview to be on portrait mode AND show it correctly (without stretching) , but now the barcode doesn't work at all . here're the changes i've made to "setDesiredCameraParameters" on "CameraConfigurationManager.java" in order to show the camera correctly :

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: 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

when i'm finished with that , i also need to customize the location&size of the rectangle to the scanning . i know that i need to change "setManualFramingRect" on "CameraManager.java" , but i'm not sure if i do 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);
}

of course ,i've changed "openDriver" to call :

if (_requestedFramingRect != null)
    setManualFramingRect(_requestedFramingRect);

please help me.


EDIT: now i've found out that it doesn't work on some devices . it crashes on the beginning , and if you debug , you can see that even the preview doesn't work well.

like image 815
android developer Avatar asked Nov 05 '22 02:11

android developer


1 Answers

There's more to it than this. For example you need to actually "rotate" the camera data (or, scan it as if it's vertical) when the camera orientation is not the same as the device orientation. And when using a front camera, you need to account for the fact that its rotation is reversed.

like image 189
Sean Owen Avatar answered Nov 11 '22 13:11

Sean Owen