我正在关注这个问题(http://code.google.com/p/zxing/issues/detail?id=178)并按照评论 #46 的说明进行操作,但三星 Galaxy s 2 没有运气。
我已经记录了它在 DecodeHandler.java 中进行旋转后接收到的图像,并且发生了一件奇怪的事情。图像似乎被校正旋转,但它上面有一个绿色过滤器(请检查下面的文件)。
有人经历过这个或有解决方案吗?
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:写入文件的代码
- 如果我在进行旋转之前传递 byte[],则此代码效果很好。
- 旋转后图像变为绿色
代码
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();
}