Android的byte []的图像在Camera.on previewFrame [英] Android byte[] to image in Camera.onPreviewFrame

查看:488
本文介绍了Android的byte []的图像在Camera.on previewFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试转换的字节[] Camera.on previewFrame Bitamp 使用 BitmapFactory.de codeByteArray 给我一个错误 SkImageDe codeR ::厂返回空

以下是我的code:

 在previewFrame公共无效(byte []的数据,摄像头摄像头){
    BMP位= BitmapFactory.de codeByteArray(数据,0,data.length);
}
 

解决方案

我发现后很长一段时间了答案。这是...

而不是使用 BitmapFactory ,我用我的自定义方法脱code本字节[]数据一个有效的图像格式。脱$ C C的图像$为有效的图像格式,人们需要通过调用<一个知道什么画面格式正在使用由摄像机href="http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getPictureFormat%28%29"相对=nofollow> camera.getParameters()。getPictureFormat() 。这个方法返回 的imageformat 。知道格式后,使用适当的EN codeR为en code中的形象。

在我的情况下,字节[]数据是在 YUV 的格式,所以我找了 YUV BMP 转换和解决我的问题。

When trying to convert the byte[] of Camera.onPreviewFrame to Bitamp using BitmapFactory.decodeByteArray gives me an error SkImageDecoder::Factory returned null

Following is my code:

public void onPreviewFrame(byte[] data, Camera camera) {
    Bitmap bmp=BitmapFactory.decodeByteArray(data, 0, data.length);
}

解决方案

I found the answer after a long time. Here it is...

Instead of using BitmapFactory, I used my custom method to decode this byte[] data to a valid image format. To decode the image to a valid image format, one need to know what picture format is being used by the camera by calling camera.getParameters().getPictureFormat(). This returns a constant defined by ImageFormat. After knowing the format, use the appropriate encoder to encode the image.

In my case, the byte[] data was in the YUV format, so I looked for YUV to BMP conversion and that solved my problem.

这篇关于Android的byte []的图像在Camera.on previewFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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