[問題] 請問如何顯示一個byte array的圖
初學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
→
09/10 17:37, , 1F
09/10 17:37, 1F
→
09/10 17:38, , 2F
09/10 17:38, 2F