BitMap、Drawable、inputStream及byte[] 互轉

(1) BitMap  to   inputStream:code

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    InputStream isBm = new ByteArrayInputStream(baos .toByteArray());orm

 

 (2)BitMap  to   byte[]:get

Bitmap defaultIcon = BitmapFactory.decodeStream(in);input

ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);it

byte[] bitmapdata = stream.toByteArray();io

 (3)Drawable  to   byte[]:stream

Drawable d; // the drawable (Captain Obvious, to the rescue!!!)
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, bitmap);
byte[] bitmapdata = stream.toByteArray();map

 

(4)byte[]  to  Bitmap :vi

Bitmap bitmap =BitmapFactory.decodeByteArray(byte[], 0,byte[].length);co

(5) inputstream   to   bitmap

Bitmap bitmap = BitmapFactory.decodeStream(is);

相關文章
相關標籤/搜索