1.Drawable—>Bitmap

Resources res=getResources();

Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.sample_0);
Resources res=getResources();
private byte[] Bitmap2Bytes(Bitmap bm){

2.Bitmap—->Drawable

Drawable drawable =new BitmapDrawable(bmp);

3、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;

}

4、从资源中获取Bitmap

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

5、Bitmap → byte[]

ByteArrayOutputStream baos = new ByteArrayOutputStream();bm.compress(Bitmap.CompressFormat.PNG, 100, baos);return baos.toByteArray();   }

6、 byte[] → Bitmap

private Bitmap Bytes2Bimap(byte[] b){

                if(b.length!=0){                        return BitmapFactory.decodeByteArray(b, 0, b.length);                }                else {                        return null;                }      }

转载自http://blog.csdn.net/hezhipin610039/article/details/7899248/

更多相关文章

  1. android 基于百度地图api获取经纬度
  2. 获取Android的APK包签名信息
  3. Android(安卓)Studio 获取数字签名信息(SHA1)
  4. 技术|Android安装包优化
  5. [整理]android中几种常见的尺寸
  6. android有用代码片段
  7. Android(安卓)获取前台应用
  8. Android之获取手机相关信息
  9. Android应用程序中创建一个http服务器

随机推荐

  1. Android技能树 — 排序算法基础小结
  2. android 写 xml时,加layout与不加的区别(如
  3. android:RecyclerView局部刷新那点事~
  4. Android开发工具——ADB(Android(安卓)De
  5. Android热更新实现原理
  6. Android入门学习:Android 系统框架及应用
  7. Android开发100G文档知识大全资料集合
  8. react-native webView android使用本地ht
  9. Android Drawable Resources系列10:
  10. Android跑马灯效果,字体滚动滚屏效果