1

I am following this issue (http://code.google.com/p/zxing/issues/detail?id=178) and followed the instructions of the comment #46 but no luck with samsung galaxy s 2.

I've recorded the image that it receives after making the rotation in DecodeHandler.java and a strange thing happens. The image appears to be corrected rotated, but it has like a green filter over it (please check file below).

enter image description here

Anyone experienced this or have a solution for this?

byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++)
        rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width; // Here we are swapping, that's the difference to #11
width = height;
height = tmp;
data = rotatedData;

PS: Code for writing to file

  • this code works great if i pass the byte[] before doing the rotation.
  • After making the rotation the image go to green

Code

 public void writeFile(byte[] data, 
                    String fileName, 
                    int width, int height) 
                    throws IOException{
  FileOutputStream out = new FileOutputStream(fileName);          
  YuvImage im = new YuvImage(data, ImageFormat.NV21, width,
          height, null);
    Rect r = new Rect(0,0,width,height);        
    im.compressToJpeg(r, 100, out);

  out.write(data);
  out.close();
}
Siddharth
  • 9,349
  • 16
  • 86
  • 148
Eduardo Pinheiro
  • 3,409
  • 3
  • 30
  • 39
  • The tweak is simple, though need a little bit of changes across multiple files. Here I have put a complete solution for this question: http://stackoverflow.com/questions/16252791/how-to-show-zxing-camera-in-portrait-mode-on-android/16252917#16252917 – Roy Lee Apr 27 '13 at 16:35

1 Answers1

1

I imagine that the problem is you are treating the input data as if it's non-planar, but it is. "Rotating" all the data like this isn't valid. You want to only look at the "Y" plane and ignore the U and V data that follows. You can rotate the Y bit as you're doing here; it's a plane.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • Hi Sean, thanks for your answer. Can you please be more precise? I never worked with images and only with your description i can understand the concept but not in a way to help me. Thanks – Eduardo Pinheiro Mar 03 '12 at 13:06
  • Read up on the YUV format. It puts all the brightness (luminance) data first -- the "Y". The rest of the data is like two smaller separate versions of the image containing color data. You want to ignore these, but your loop is mixing it in as if it's more of the Y plane. – Sean Owen Mar 03 '12 at 16:47
  • Have you found a solution fort his? – Gabor Peto May 14 '14 at 12:13