Reputation: 3789
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).
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
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();
}
Upvotes: 1
Views: 1571
Reputation: 66891
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.
Upvotes: 1