【发布时间】:2015-06-21 15:10:36
【问题描述】:
我正在尝试使用新的相机 API。突发捕获太慢了,所以我在 ImageReader 中使用 YUV_420_888 格式并稍后进行 JPEG 编码,如下面的帖子所述:
Android camera2 capture burst is too slow
问题是当我尝试使用 RenderScript 从 YUV_420_888 编码 JPEG 时,我得到绿色图像,如下所示:
RenderScript rs = RenderScript.create(mContext);
ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(rs));
Type.Builder yuvType = new Type.Builder(rs, Element.YUV(rs)).setX(width).setY(height).setYuvFormat(ImageFormat.YUV_420_888);
Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
in.copyFrom(data);
yuvToRgbIntrinsic.setInput(in);
yuvToRgbIntrinsic.forEach(out);
Bitmap bmpout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
out.copyTo(bmpout);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmpout.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] jpegBytes = baos.toByteArray();
数据变量(YUV_420_888数据)来自:
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
我在 JPEG 编码中做错了什么以使图像仅显示为绿色?
提前致谢
已编辑:这是我获得的绿色图像示例:
https://drive.google.com/file/d/0B1yCC7QDeEjdaXF2dVp6NWV6eWs/view?usp=sharing
【问题讨论】:
-
FWIW,YUV 值为 0,0,0 是中绿色。因此,如果您的图像完全是绿色的,我猜您正在转换一个充满零的缓冲区,而不是一个充满 YUV 像素数据的缓冲区。
-
我已经用我获得的图像示例编辑了这个问题。它们并不完全是绿色的,它似乎是绿色的。我认为这是因为我只从 YUV 格式的三个平面中的第一个平面获取数据。我已经搜索了一种从三个平面获取信息并将其传递给 RenderScript 的方法,但我无法使我找到的小代码工作。
-
嗨,你解决了这个问题吗?
-
我试过你的代码,保存的 png 图像是绿色的。似乎 ScriptIntrinsicYuvToRGB 无法将 YUV_420_888 转换为位图。您是否找到其他方法来实现它?
标签: android android-camera android-5.0-lollipop rgb yuv