在android系统BitmapFactory空问题 [英] BitmapFactory null issue in android
问题描述
我想创建一个使用bitmapfactory位图类。我得到相机preVIEW图像YUV格式和去code手动灰度图像。当我尝试创建位图对象通过BitmapFactory返回null。
{尝试
对于(INT Y = 0; Y< frameHeight; Y ++){
为(中间体X = 0; X&下; frameWidth; X ++){ 字节灰色= YUVData [Y * frameWidth + X];
convertedData [Y *步幅+ 3 * X] =灰色;
convertedData [Y *步幅+ 3 * X + 1] =灰色;
convertedData [Y *步幅+ 3 * X + 2] =灰色; }
} 位图位=(位图)BitmapFactory.de codeByteArray的(convertedData,0,convertedData.length);
BitmapFactory用于创建,这是连接使用JPEG或PNG $ C $光盘映像文件的图像。如果你只是在它折腾的原始数据,功能不知道你用什么编码。 RGB? YUV? 24位? 32位?
AFAIK有创建从YUV数据的图像没有原生的方式,你至少也得把它转换先RGB。这里是一个演示了一个答案:充分利用视频图像帧的Android 。
当然,你可以使用NDK创建本机转换功能,这将是快了很多。或者你可以扫描一个YUV转换的文件,但我在一个快速扫描发现的唯一的事情是的 YuvImage ,这将只允许您将此转换为JPEG视频流。
I am trying to create bitmap class using bitmapfactory. I get camera preview image in YUV format and decode manually to grayscale image. When i try to create bitmap object via BitmapFactory it returns null.
try {
for (int y = 0; y < frameHeight; y++){
for (int x = 0; x < frameWidth; x++){
byte grey = YUVData[y * frameWidth + x];
convertedData[y * stride + 3 * x] = grey;
convertedData[y * stride + 3 * x + 1] = grey;
convertedData[y * stride + 3 * x + 2] = grey;
}
}
Bitmap bitmap =(Bitmap) BitmapFactory.decodeByteArray(convertedData, 0, convertedData.length);
BitmapFactory is used to create an image from a image file that was encoded using JPEG or PNG. If you just toss raw data at it, the function has no idea what encoding you're using. RGB? YUV? 24-bit? 32-bit?
AFAIK there's no native way to create an image from YUV data, you'd at least have to convert it to RGB first. Here is an answer that demonstrates it: Getting frames from Video Image in Android.
Of course, you can use the NDK to create a native conversion function, which will be a lot faster. Or you could scan the documentation for a YUV converter, but the only thing I found in a quick scan is YuvImage, which will only allow you to convert this to a JPEG stream.
这篇关于在android系统BitmapFactory空问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!