android byte數組,bitmap,drawable之間的轉換

1.Byte數組轉Bitmap

BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
2.Bitmap轉Byte數組

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
bytes = baos.toByteArray();
3.Drawable轉Bitmap

Drawable d=xxx; //xxx根據自己的情況獲取drawable
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
4.Bitmap轉Drawable

Bitmap bm=xxx; //xxx指獲取的bitmap
BitmapDrawable bd=BitmapDrawable(bm);




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章