zxing 中 renderCroppedGreyscaleBitmap()如何得到彩色图

 

 

public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;

    for (int y = 0; y < height; y++) {
      int outputOffset = y * width;
      for (int x = 0; x < width; x++) {
      int grey = yuv[inputOffset + x] & 0xff;         
        pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);     
        
      }
      inputOffset += dataWidth;
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
  }
}

以上得到的灰度图,现在要彩色图,该怎么做呢?

这一句 pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);  二值, 肯定是要去掉的。

最关键的就是 int grey = yuv[inputOffset + x] & 0xff;    没有查到相关资料,自己试了一下,0xff 改成 0xff0000ff 0xff00ff00  0xffff0000 能分别得到不同色彩的图 ,但如何能得到彩色的原图呢?