Android的byte []的图像在Camera.on previewFrame [英] Android byte[] to image in Camera.onPreviewFrame
问题描述
在尝试转换的字节[]
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屋!