正如标题所说,如何使用 ScriptIntrinsicColorMatrix 将位图 RGB 转换回 YUV byte[]?下面是示例代码(不能被zxing解码):
public byte[] getYUVBytes(Bitmap src, boolean initOutAllocOnce){
if(!initOutAllocOnce){
outYUV = null;
}
if(outYUV == null){
outYUV = Allocation.createSized(rs, Element.U8(rs), src.getByteCount());
}
byte[] yuvData = new byte[src.getByteCount()];
Allocation in;
in = Allocation.createFromBitmap(rs, src,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
scriptColor.setRGBtoYUV();
scriptColor.forEach(in, outYUV);
outYUV.copyTo(yuvData);
return yuvData;
}
我注意到的一件事是原始相机 YUV 字节为 3110400 字节,但在使用 ScriptIntrinsicColorMatrix 转换后变为 8294400,我认为这是错误的。
YUV -> BW -> YUV 的原因是我想将图像转换为黑白(不是灰度)并返回 YUV 以进行 zxing 解码,同时在 Surfaceview 中显示黑白(如自定义相机滤镜) .
尝试了下面的代码,但它有点慢(可以通过 zxing 解码)。
int[] intArray = null;
intArray = new int[bmp.getWidth() * bmp.getHeight()];
bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
LuminanceSource source = new RGBLuminanceSource(cameraResolution.x, cameraResolution.y, intArray);
data = source.getMatrix();
RGB 到 YUV 的任何其他快速替代方案?如果 ScriptIntrinsicColorMatrix 类无法完成?
谢谢,麻烦您了