码迷,mamicode.com
首页 > 移动开发 > 详细

android Drawable转Bitmap| Bitmap转byte[]

时间:2014-12-17 00:23:44      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:android bitmap drawa

//

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


//

 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);
  drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
    drawable.getIntrinsicHeight());
  drawable.draw(canvas);
  return bitmap;
 }

android Drawable转Bitmap| Bitmap转byte[]

标签:android bitmap drawa

原文地址:http://blog.csdn.net/u011636207/article/details/41969587

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!