我正在从相机中检索原始图像,图像的规格如下:
> 80 x 60分辨率
> 4位灰度
我将图像检索为字节数组,并具有2400(1/2 * 80 * 60)字节长的数组.下一步是将字节数组转换为位图.我已经用过了
BitmapFactory.decodeByteArray(bytes,bytes.length)
但是没有返回可显示的图像.我查看了this post并将下面的代码复制到我的Android应用程序中,但是我得到了一个“不足以容纳像素的缓冲区”运行时错误.
byte [] Src; //Comes from somewhere...
byte [] Bits = new byte[Src.length*4]; //That's where the RGBA array goes.
int i;
for(i=0;i
{
Bits[i*4] =
Bits[i*4+1] =
Bits[i*4+2] = ~Src[i]; //Invert the source bits
Bits[i*4+3] = -1;//0xff,that's the alpha.
}
//Now put these nice RGBA pixels into a Bitmap object
Bitmap bm = Bitmap.createBitmap(Width,Height,Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(ByteBuffer.wrap(Bits));
在帖子的底部,原始海报与我目前有相同的错误.但是,他的问题已通过上面粘贴的代码修复.有没有人对如何将原始图像或RGBA数组转换为位图