作者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