1

我正在关注这个问题(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();
}
4

1 回答 1

1

我想问题在于您将输入数据视为非平面的,但确实如此。像这样“旋转”所有数据是无效的。您只想查看“Y”平面并忽略随后的 U 和 V 数据。您可以像在这里一样旋转 Y 位;这是一架飞机。

于 2012-03-02T23:24:19.160 回答