2
我想將Yuv中的byte []轉換爲Rgb中的byte []。 ScriptIntrinsic(ScriptIntrinsicYuvToRgb)應該這樣做(基於此example)。執行ScriptIntrinsicYuvToRgb
下面是一些代碼,我現在所擁有的:
byte[] imageData = ...gatheryuvbuffer...
Type.Builder tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
tb.setX(outputWidth);
tb.setY(outputHeight);
tb.setMipmaps(false);
tb.setYuvFormat(ImageFormat.NV21);
Allocation ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
ain.copyFrom(imageData);
Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS));
tb2.setX(outputWidth);
tb2.setY(outputHeight);
tb2.setMipmaps(false);
// Allocation aOutBitmap = Allocation.createFromBitmap(mRS, bitmap);
Allocation aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_IO_OUTPUT);
aOut.setSurface(null);
mYuvToRgb.setInput(ain);
mYuvToRgb.forEach(aOut);
Bitmap bitmap = Bitmap.createBitmap(outputWidth, outputHeight, Bitmap.Config.ARGB_8888);
aOut.copyTo(bitmap);
利用這個腳本的最後,我想到位圖包含的東西(我在ImageView的顯示它)。但是位圖顯示爲空白。這段代碼片段有什麼問題?
就是這樣!我還必須刪除setSurface(null)調用。 –