一直接触这些东西,还是归个类整理一下比较好。

Resource -> Drawable

Drawable draw1 = this.getResources().getDrawable(R.drawable.icon);

Drawable -> Bitmap

1.

static Bitmap drawableToBitmap(Drawable drawable) // drawable 转换成bitmap
{
int width = drawable.getIntrinsicWidth();// 取drawable的长宽
int height = drawable.getIntrinsicHeight();
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ?Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565;// 取drawable的颜色格式
Bitmap bitmap = Bitmap.createBitmap(width, height, config);// 建立对应bitmap
Canvas canvas = new Canvas(bitmap);// 建立对应bitmap的画布
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);// 把drawable内容画到画布中
return bitmap;
}

2.

Bitmap bitmap = ((android.graphics.drawable.BitmapDrawable) pm.getApplicationIcon(appInfo)).getBitmap();

简单谈谈Resource,Drawable和Bitmap之间的转换的更多相关文章

  1. 图片文件和Bitmap之间的转换

    图片文件转为Bitmap对象String filePath="c:/01.jpg";  Bitmap bitmap=BitmapFactory.decodeFile(filePat ...

  2. Android 图片文件和Bitmap之间的转换

    String filePath="c:/01.jpg"; Bitmap bitmap=BitmapFactory.decodeFile(filePath); 如果图片过大,可能导致 ...

  3. Drawable和Bitmap区别

    Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一种存储对象比较好 ...

  4. JavaBean和json数据之间的转换(一)简单的JavaBean转换

    1.为什么要使用json? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,因为其高性能.可读性强的原因,成为了现阶段web开发中前后端交互数据的主要数据 ...

  5. JavaBean和json数据之间的转换(二)含有date类型的JavaBean

    1.前言 上次讲了简单的JavaBean和json格式之间的转换,代码很简单,但是实际过程中,往往用到的JavaBean都是比较复杂的,其他的字段还好,如果JavaBean中包含了date类型的字段, ...

  6. Android中Bitmap, Drawable, Byte,ID之间的转化

    Android中Bitmap, Drawable, Byte,ID之间的转化 1.  Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...

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

    android在处理一写图片资源的时候,会进行一些类型的转换: 1 Drawable → Bitmap 的简单方法 ((BitmapDrawable)res.getDrawable(R.drawabl ...

  8. Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】

    package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...

  9. Android图片二进制与Bitmap、Drawable之间的转换

    Android图片二进制与Bitmap.Drawable之间的转换 Java代码  public byte[] getBitmapByte(Bitmap bitmap){      ByteArray ...

随机推荐

  1. php数组函数

    1.键值函数 array_values()返回数组元素值,组成一个新的索引数组 2.array_keys()返回数组所有键名,组成一个索引数组 3.in_array()检查数组中是否存在某个值 4.a ...

  2. iframe空文档中写入内容

    往一个空的iframe中写入内容,再其document ready之前有可能遇到拿回 的body指针为空,因此以下面的函数往其document中写入html HRESULT WriteToHtmlDo ...

  3. 推送XML

    推送的连接地址如:www.baidu.com /// <summary> /// 提交数据 /// </summary> /// <param name="ms ...

  4. 【动态规划】bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝

    将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #incl ...

  5. Activity的四种启动模式详解

    Activity的启动模式在清单文件AndroidManifest.xml中的Activity属性中进行设置: 如:<activity android:name=".MainActiv ...

  6. window.opener强大功能

    window.opener后面的方法可以调用任意父窗口里面js的方法. eg.query()是父窗口的 function refreshParent(){   window.opener.query( ...

  7. HDFS用户指南

    https://hadoop.apache.org/docs/r1.2.1/hdfs_user_guide.html hdfs的一些特征: 1.hadoop 包含hdfs 很适合分布式存储以及分布式处 ...

  8. PHP接口使用

    <?php interface IEmployee { function working(); } interface IDeveloper { function Coding(); } cla ...

  9. 【Win10】UAP/UWP/通用 开发之 SplitView

    [Some information relates to pre-released product which may be substantially modified before it's co ...

  10. [译]面向初学者的Asp.Net状态管理技术

    介绍 本文主要讲解Asp.Net应用程序中的状态管理技术(Asp.Net中有多种状态管理技术),并批判性地分析所有状态管理技术的优缺点. 背景 HTTP是无状态的协议.客户端发起一个请求,服务器响应完 ...