`
mapeijie888
  • 浏览: 993 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

android Bitmap Drawable bitByte[] 互相转换

阅读更多
转换Bitmap to Drawable
BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap;    
Drawable drawable = (Drawable)bitmapDrawable;       
    
Bitmap bitmap = new Bitmap (...);    
Drawable drawable = new BitmapDrawable(bitmap); 

转换Drawable to Bitmap
Drawable d = ImagesList.get(0); 
Bitmap bitmap = ((BitmapDrawable)d).getBitmap(); 

转换Bitmap to byte[]
private byte[] Bitmap2Bytes(Bitmap bm){ 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();   
     bm.compress(Bitmap.CompressFormat.PNG, 100, baos);   
     return baos.toByteArray(); 


转换byte[] to Bitmap
private Bitmap Bytes2Bimap(byte[] b){ 
    if(b.length!=0){ 
        return BitmapFactory.decodeByteArray(b, 0, b.length); 
    }else { 
        return null; 
    } 
}
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics