感谢Alex
Cohn,感谢他帮助我加快了转换速度。我实现了您建议的方法(Renderscript内部函数)。该代码由Renderscript内在函数构成,可将YUV图像转换为位图的速度约快5倍。先前的代码花费了100-150毫秒。在三星Note
3上,这需要15到30左右。 如果有人需要执行相同的任务,则代码如下:
这些将用于:
private Renderscript rs;private scriptIntrinsicYuvToRGB yuvToRgbIntrinsic;private Type.Builder yuvType, rgbaType;private Allocation in, out;
在创建函数中,我初始化..:
rs = Renderscript.create(this);yuvToRgbIntrinsic = scriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
整个onPreviewframe看起来像这样(在这里我接收并转换图像):
if (yuvType == null){ yuvType = new Type.Builder(rs, Element.U8(rs)).setX(dataLength); in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_script); rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(prevSizeW).setY(prevSizeH); out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_script);}in.copyFrom(data);yuvToRgbIntrinsic.setInput(in);yuvToRgbIntrinsic.forEach(out);Bitmap bmpout = Bitmap.createBitmap(prevSizeW, prevSizeH, Bitmap.Config.ARGB_8888);out.copyTo(bmpout);


