将zxing条形码扫描仪切换为纵向模式

时间:2012-03-02 19:40:26

标签: android barcode zxing portrait

我正在关注此问题(http://code.google.com/p/zxing/issues/detail?id=178),并按照评论#46的说明进行操作,但三星Galaxy s 2没有运气。

我在DecodeHandler.java中进行了旋转后记录了它收到的图像 一件奇怪的事情发生了。图像似乎是旋转校正的,但它上面有一个绿色滤镜(请查看下面的文件)。

enter image description here

任何人都经历过这个或有解决方案吗?

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();
}

1 个答案:

答案 0 :(得分:1)

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

相关问题