Java android renderscript ScriptIntrinsicColorMatrix setRGBtoYUV示例用法

Java android renderscript ScriptIntrinsicColorMatrix setRGBtoYUV示例用法,java,android,zxing,renderscript,android-renderscript,Java,Android,Zxing,Renderscript,Android Renderscript,正如标题所述,如何使用ScriptIntrinsicColorMatrix将位图RGB转换回YUV字节[]?以下是示例代码(zxing无法解码): 我注意到的一件事是,从最初的camera中,YUV字节是3110400字节,但在中使用ScriptIntrinsicColorMatrix转换后变成了8294400,我认为这是错误的 YUV->BW->YUV的原因是我想将图像转换为黑白(而不是灰度)并返回YUV,以便zxing解码,同时在surfaceview中显示黑白(如自定义相机过滤器) 尝试下

正如标题所述,如何使用ScriptIntrinsicColorMatrix将位图RGB转换回YUV字节[]?以下是示例代码(zxing无法解码):

我注意到的一件事是,从最初的camera中,YUV字节是3110400字节,但在中使用ScriptIntrinsicColorMatrix转换后变成了8294400,我认为这是错误的

YUV->BW->YUV的原因是我想将图像转换为黑白(而不是灰度)并返回YUV,以便zxing解码,同时在surfaceview中显示黑白(如自定义相机过滤器)

尝试下面的代码,但有点慢(可以由zxing解码)

RGB到YUV还有其他快速的替代方案吗?如果无法完成ScriptIntrinsicColorMatrix类


请并感谢您

zxing标记在该代码中的作用是什么?使用zxing的RGBLuminanceSource类,将byte[]原始图像传递给zxing以解码qr代码,但从RGBLuminanceSource到byte[]数据的int数组有点慢,并导致延迟,尝试使用ScriptIntrinsicColorMatrix,但在zxing上无法将rgb转换为YUV格式的输入
位图
,还是rgb格式?代码读起来就像是在RGB中,您试图将其转换为YUV,但您的问题的措辞就像是YUV,您试图对其应用黑白处理。位图是RGB格式的,因为位图无法容纳YUV颜色空间
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;
}
  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();