1、Drawable → Bitmap

public static Bitmap drawableToBitmap(Drawable drawable) {                Bitmap bitmap = Bitmap                        .createBitmap(                                        drawable.getIntrinsicWidth(),                                        drawable.getIntrinsicHeight(),                                        drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888                                                        : Bitmap.Config.RGB_565);        Canvas canvas = new Canvas(bitmap);        //canvas.setBitmap(bitmap);        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());        drawable.draw(canvas);        return bitmap;}

2、从资源中获取Bitmap

Resources res=getResources();Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);

3、Bitmap → byte[]

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

4、 byte[] → Bitmap

private Bitmap Bytes2Bimap(byte[] b){    if(b.length!=0){    return BitmapFactory.decodeByteArray(b, 0, b.length);    }    else {    return null;    }  }

更多相关文章

  1. 八款开源 Android 游戏引擎 (巨好的资源)
  2. Android 之 将RAW资源文件写入SD卡工具类
  3. Android相关网络资源整理
  4. 一个android访问http资源的便捷工具类――HttpHelper
  5. Android学习资源-retrofit,eventBus,butterknife,fragment
  6. 【Demo 0005】Android 资源
  7. 很好的资源学习入口_android

随机推荐

  1. 深入理解 ProtoBuf 原理与工程实践(概述)
  2. 高性能缓存 Caffeine 原理及实战
  3. php学习笔记(20个常用的字符串函数)
  4. Linux字符的查看及修改
  5. [牛客习题]任意进制转换
  6. 排除故障就像探案——记一次摄像头信号卡
  7. [牛课习题]判断字符串是否回文及统计回文
  8. 0202-类声明及类的实例化,静态成员与类的
  9. PHP初级变量类型转换与变量和常量的声明
  10. anaconda和pycharm区别是什么?Python学习