android在处理一写图片资源的时候,会进行一些类型的转换:

1 Drawable → Bitmap 的简单方法

 ((BitmapDrawable)res.getDrawable(R.drawable.youricon)).getBitmap();

2 Drawable → Bitmap

 public static Bitmap drawableToBitmap(Drawable drawable) {  

     Bitmap bitmap = Bitmap.createBitmap(rawable.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;
}

3 Bitmap→Drawable的简单方法

 BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap;
Drawable drawable = (Drawable)bitmapDrawable; Bitmap bitmap = new Bitmap (...);
Drawable drawable = new BitmapDrawable(bitmap);

4 从资源中获取Bitmap

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

5 Bitmap → byte[]

 private byte[] Bitmap2Bytes(Bitmap bm) {
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;
}
}

Drawable、Bitmap、byte[]之间的转换的更多相关文章

  1. Stream 和 byte[] 之间的转换

    Stream 和 byte[] 之间的转换 一. 二进制转换成图片 ? 1 2 3 4 5 MemoryStream ms = new MemoryStream(bytes); ms.Position ...

  2. C#实现Stream与byte[]之间的转换实例教程

    一.二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream(m ...

  3. C# Stream 和 byte[] 之间的转换

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  4. C# Stream 和 byte[] 之间的转换(文件流的应用)

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  5. 将String转化成Stream,将Stream转换成String, C# Stream 和 byte[] 之间的转换(文件流的应用)

    static void Main( string[] args ) { string str = "Testing 1-2-3"; //convert string 2 strea ...

  6. C#下载文件,Stream 和 byte[] 之间的转换

    stream byte 等各类转换 http://www.cnblogs.com/warioland/archive/2012/03/06/2381355.html using (System.Net ...

  7. Android Drawable、Bitmap、byte[]之间的转换

    转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...

  8. Image与byte[]之间的转换

    //将image转化为二进制 public static byte[] GetByteImage(Image img) { byte[] bt = null; if (!img.Equals(null ...

  9. C#--整型与字节数组byte[]之间的转换

    using System; int  i = 123;byte [] intBuff = BitConverter.GetBytes(i);     // 将 int 转换成字节数组lob.Write ...

随机推荐

  1. HDU2167+状态压缩DP

    状态压缩dp 详见代码 /* 状态压缩dp dp[ i ][ j ]:第i行j状态的最大和 dp[i][j] = max( dp[i-1][k]+sum[i][j] ); 题意:给定一个N*N的方格, ...

  2. 万能脚本助Web执行底层Linux命令

    需求分析: 这里先要说明的是,这一篇不是QT系列的文章,而是关于Web的,之所以要写这篇,是因为以前做Web相关开发的时候,经常涉及到与linux底层命令打交道,比如说创建一个目录,删除一个目录,或者 ...

  3. SSO(转)

    一.介绍       主站下有多个子系统,每次登录主系统,跳转到子系统时,又需要重新登录: 子系统与主系统都有各自的用户信息表:各个系统的用户角色.权限也各不相同: 二.目的       每次登录主系 ...

  4. 坑爹的UICollectionView

    最近用UICoolectionView的时候遇到一个很DT的问题,我往VC里加12个视图,结果显示成这样(右边是期待的样子):       研究了一下午,终于发现了问题: @interface FpL ...

  5. bzoj2661

    不难想到,先枚举建图然后跑最大费用最大流 也不难想到一种将每个数拆成两个点i1,i2,所有满足条件的数之间 把所有满足条件之间的数x,y连边x1--->y2,y1--->x2,流量为1,费 ...

  6. WordPress Checkout插件跨站脚本漏洞和任意文件上传漏洞

    漏洞名称: WordPress Checkout插件跨站脚本漏洞和任意文件上传漏洞 CNNVD编号: CNNVD-201311-015 发布时间: 2013-11-04 更新时间: 2013-11-0 ...

  7. 物联网操作系统HelloX V1.77(beta)版本发布

    物联网操作系统HelloX V1.77发布 经过近半年的努力,物联网操作系统HelloX V1.77版本正式完成,源代码已上载到github(github.com/hellox-project/Hel ...

  8. Sharepoint 2010 根据用户权限隐藏Ribbon菜单

    转:http://xiangzhangjun2006.blog.163.com/blog/static/44140966201211715416178/   1.使用SPD打开站点,并打开母版页.默认 ...

  9. .9.png

    .9.png是一种非失真性压缩位图图形文件格式.PNG格式是非失真性压缩的,允许使用类似于GIF格式的调色板技术,支持真彩色图像,并具备阿尔法通道(半透明)等特性.现在有很多人使用PNG格式于互联网及 ...

  10. Codeforces 302D

    思路:最短路,map[i][j] = d*(|x[i]-x[j]| + |y[i]-y[j]|) - add[i] #include<iostream> #include<cstdi ...