将 android.media.Image (YUV_420_888) 转换为 Bitmap [英] Convert android.media.Image (YUV_420_888) to Bitmap

查看:139
本文介绍了将 android.media.Image (YUV_420_888) 转换为 Bitmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此处提出的 camera2 api 实现相机预览图像数据处理:使用 Android L 和 Camera2 API 处理相机预览图像数据.

I'm trying to implement camera preview image data processing using camera2 api as proposed here: Camera preview image data processing with Android L and Camera2 API.

我使用 onImageAvailableListener 成功接收到回调,但为了以后的处理,我需要从 YUV_420_888 android.media.Image 获取位图.我搜索了类似的问题,但都没有帮助.

I successfully receive callbacks using onImageAvailableListener, but for future processing I need to obtain bitmap from YUV_420_888 android.media.Image. I searched for similar questions, but none of them helped.

您能否建议我如何将 android.media.Image (YUV_420_888) 转换为 Bitmap 或者有更好的方式来监听预览帧?

Could you please suggest me how to convert android.media.Image (YUV_420_888) to Bitmap or maybe there's a better way of listening for preview frames?

推荐答案

我写了一些关于这个的代码,它是 YUV 数据预览并将其转换为 JPEG 数据,我可以用它来保存为位图 ,byte[],或其他.(您可以看到类分配").

并且 SDK 文档说:
为了使用 android.renderscript 进行高效的 YUV 处理:使用支持的 YUV 类型、IO_INPUT 标志和 getOutputSizes(Allocation.class) 返回的大小之一创建 RenderScript Allocation,然后获取表面与 getSurface()."

下面是代码,希望对你有帮助:https://github.com/pinguo-yuyidong/Camera2/blob/master/camera2/src/main/rs/yuv2rgb.rs

I write some code about this, and it's the YUV datas preview and chang it to JPEG datas ,and I can use it to save as bitmap ,byte[] ,or others.(You can see the class "Allocation" ).

And SDK document says:
"For efficient YUV processing with android.renderscript: Create a RenderScript Allocation with a supported YUV type, the IO_INPUT flag, and one of the sizes returned by getOutputSizes(Allocation.class), Then obtain the Surface with getSurface()."

here is the code, hope it will help you:https://github.com/pinguo-yuyidong/Camera2/blob/master/camera2/src/main/rs/yuv2rgb.rs

这篇关于将 android.media.Image (YUV_420_888) 转换为 Bitmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆