Yam*_*gut 10 rgb android yuv android-camera android-5.0-lollipop
我正在尝试使用新的相机api.突发捕获速度太慢,因此我在ImageReader中使用YUV_420_888格式并稍后进行JPEG enconding,如以下帖子中所示:
问题是当我尝试使用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();
Run Code Online (Sandbox Code Playgroud)
数据变量(YUV_420_888数据)来自:
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
Run Code Online (Sandbox Code Playgroud)
我在JPEG编码中做错了什么才能使图像只显示为绿色?
提前致谢
编辑:这是我获得的绿色图像的示例:
https://drive.google.com/file/d/0B1yCC7QDeEjdaXF2dVp6NWV6eWs/view?usp=sharing
如果我正确理解您的描述,我可以在您的代码中看到至少两个问题:
看来您只将图像的 Y 部分传递给 YUV->RGB 转换代码,因为看起来您只使用 中的第一个平面ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();,而忽略了 U 和 V 平面。
我还不熟悉这些 Renderscript 类型,但看起来 Element.RGBA_8888 和 Bitmap.Config.ARGB_8888 引用的字节顺序略有不同,因此您可能需要进行一些重新排序工作。
这两个问题都可能是导致生成的图片呈绿色的原因。
| 归档时间: |
|
| 查看次数: |
5707 次 |
| 最近记录: |