作者VoidPtr (泛用指针)
看板AndroidDev
标题[问题] 显示一个byte array的图
时间Wed Sep 5 17:36:20 2012
初学android,这该是个很蠢的问题。
请问如何将 byte array的图显示呢?
试了好久还是不行啊,摸了一下後一样还是显示底图,不是我乱填的资料图。
有没高手能提示下再下呢? 谢谢。
public boolean onTouch(View v, MotionEvent event) {
ImageView iv = (ImageView) v;
int width, height;
width = iv.getWidth();
height = iv.getHeight();
int dataLengh = width*height*4;
byte[] imageData = new byte[dataLengh];
/*乱填一堆资料*/
for(int j = 0; j< height; j++){
for(int i = 0; i< width; i++){
int index;
index = 4*(i + width*j);
imageData[index] = 64;
imageData[index + 1] = 64;
imageData[index + 2] = 64;
imageData[index + 3] = 64;
}
}
Bitmap bitmap = null;
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeByteArray(imageData, 0, dataLengh, opt);
iv.setImageBitmap(bitmap);
return false;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 116.59.229.208
1F:→ h124224:要先把stream强制转成你要的档案类型 09/10 17:37
2F:→ h124224:我没读过图档 不过之前处理stream都这样做 @@ 09/10 17:38