0

I successfully integrated ZXing Library in my app, but there is a weird problem that I am encountering during scanning.

As you can see here

enter image description here

I am able to center the Scanning area to my custom view by passing the canvas width and height to the CameraManager Class Like this, so I can set the preview size and location to where I want it to be.

public void onDraw(Canvas canvas) {
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    //give the framing preview the canvas width and size
    CameraManager.get().giveCanSize(width, height);

//Some more code

But the problem now is, If I place a barcode image in the CENTER or LEFT part of the viewfinder (The clear area surrounded by darkened borders) , it does not scan it, Like it does not see it, BUT, whenever I place the barcode image on the RIGHT portion of the view finder, it scans it. Can someone tell me where did I mess up? or did I miss something?

some part of the modified framingRect method

//modified framing rectangle, depends entirely on the canvas size
      int left = (canvasWidth / 2) - (width / 2);
      int top = (canvasHeight / 2) - (height / 2);
      int right = (canvasWidth / 2) + (width / 2);
      int botm = (canvasHeight / 2) + (height / 2);
      framingRect = new Rect(left, top, right, botm);
      Log.d(TAG, "Calculated framing rect: " + framingRect);

    }
    return framingRect;

I hope someone can help me, TIA!

Prasanth S
  • 3,549
  • 8
  • 41
  • 73
  • You should check your SurfaceView, and make sure it is configured correctly. Try to dump the preview data to check whether the preview data is right. The canvas is only used to draw graphics effect on surfaceView. It won't affect whether the barcode can be recognized or not. – yushulx Apr 18 '14 at 08:23
  • Hmm, I did not do anything on the surfaceView, what I did was, Include the library on my app, then I set the camera orientation (and my app orientation) to portrait. Preview data? hmm, can you show me how to do it? I've been playing and analyzing the code for sometime and I really can't see the code where the scanning area is placed :( – Kratellismorru Apr 21 '14 at 07:55
  • You can set application orientation landscape in Manifest. If you use the portrait mode, the preview data is rotated. To detect the rotated barcode, you need to pass the data with an angle. I'm not sure whether ZXing support this. If not, you have to rotate your preview data yourself. The image format of preview data is NV21, you can refer [YuvImage](http://developer.android.com/reference/android/graphics/YuvImage.html) to save the data. – yushulx Apr 22 '14 at 02:27
  • Ok, I'll try it, I guess I have to refer to this one http://stackoverflow.com/questions/16252791/zxing-camera-in-portrait-mode-on-android/16252917#16252917 for further fixes, – Kratellismorru Apr 28 '14 at 11:37
  • ZXing should be able to find the qr code in the rotated preview image. Instead of rotating the preview image you can draw the found qr coordinates on a canvas and rotate the canvas. – bcorso Aug 12 '14 at 17:47

0 Answers0