android Bitmap和Drawable的区别
Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565、RGB888。作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低。我们理解为一种存储对象比较好。
Drawable - 作为Android平下通用的图形对象,它可以装载常用格式的图像,比如GIF、PNG、JPG,当然也支持BMP,当然还提供一些高级的可视化对象,比如渐变、图形等。
A bitmap is a Drawable. A Drawable is not necessarily a bitmap. Like all thumbs are fingers but not all fingers are thumbs.
Bitmap是Drawable . Drawable不一定是Bitmap .就像拇指是指头,但不是所有的指头都是拇指一样.
The API dictates: API规定:
Though usually not visible to the application, Drawables may take a variety of forms: 尽管通常情况下对于应用是不可见的,Drawables 可以采取很多形式:
Bitmap: the simplest Drawable, a PNG or JPEG image. Bitmap: 简单化的Drawable, PNG 或JPEG图像.
Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
States: a compound drawable that selects one of a set of drawables based on its state.
Levels: a compound drawable that selects one of a set of drawables based on its level.
Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.
对比项 | 显示清晰度 | 支持透明色 | 支持色相色差调整 | 支持像素操作 |
---|---|---|---|---|
Bitmap | 相同 | 是 | 是 | 是 |
Drawable | 相同 | 是 | 否 | 否 |
Drawable在内存占用和绘制速度这两个非常关键的点上胜过Bitmap
- Drawable和Bitmap之间可以互相转换,Drawable占用内存远小于Bitmap。
- setImageDrawable使用资源文件;setImageBitmap使用bitmap图片,该图片可能是读取本地相册,或者从资源文件转换而来。
- setImageResource()和setImageBitmap()
//setImageResource()
public void setImageResource (int resId)//占用UI thread;
// setImageBitmap()
ImageView iv;
String fileName = "/data/data/com.test/aa.png";
Bitmap bm = BitmapFactory.decodeFile(fileName);
iv.setImageBitmap(bm); //占用内存
// setImageBitmap()
Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(image);
// Bitmap转换成Drawable
Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
BitmapDrawable bitmapDrawable = new BitmapDrawable(image);
imageView.setImageDrawable(bitmapDrawable);
// 结论:Bitmap是Drawable . Drawable不一定是Bitmap
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
小结
Bitmap: 简单化的Drawable, PNG 或JPEG图像.
Drawable在内存占用和绘制速度这两个非常关键的点上胜过Bitmap
android Bitmap和Drawable的区别相关推荐
- android bitmap对比,Android Bitmap和Drawable的对比
Android Bitmap和Drawable的对比 Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但 ...
- Bitmap 和Drawable 的区别
Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一种存储对象比较好 ...
- (转)Android Bitmap 与 Drawable之间的转换
转换Bitmap to Drawable Bitmap bitmap = new Bitmap (...); Drawable drawable = new BitmapDrawable(bitmap ...
- android bitmap 转drawable,android Drawable转换成Bitmap失败
错误代码: 08-07 06:42:30.482 28497-28497/app.tianxiayou E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: ...
- android bitmap转drawable
BitmapDrawable bd = (BitmapDrawable) drawable;
- android mipmap的作用,Android 中的mipmap 和drawable的区别
在android studio中我们创建项目后,在资源res文件中有drawable和mipmap两种存放图片的文件夹,在使用哪一个文件夹来存放图片,一直都很有争议: android 在 API le ...
- android bitmap转图片_Android 这些 Drawable 你都会用吗?
在实际开发的过程中,除了广为人知的利用 StateListDrawable 设置按钮点击特效,我们有时可能会接到一些这样的需求,比如要求我们的头像显示成圆形或者圆角矩形,甚至要加上可变颜色的边框,或者 ...
- android bitmap drawable 互转
引用: http://www.android123.com.cn/kaifafaq/704.html 很多开发者表示,不知道Android的Drawable和Bitmap之间如何相关转换.下面And ...
- Android 中 资源文件图片转 Bitmap 和 Drawable 以及相互转换的方法
Android 图片转换的方法总结: 一.Bitmap 转换成 Drawable 对 Bitmap 进行强制转换 Drawable drawable = new BitmapDrawable(bmp) ...
最新文章
- 真正实现与人更类似的智能!Jeff Hawkins:创造机器智能的路线图
- Snap和Flatpak 通吃所有发行版的打包方式。
- JSP_运维_JSP项目部署到server(适合0经验新手)
- JS类型判断、对象克隆、数组克隆
- Oracle感慨(转)
- jvm性能调优实战 - 44Metaspace区域是如何因为类太多而发生内存溢出OOM
- 文献记录(part97)--MethodicallyUnifiedProcedures for a ConditionalApproachToOD,Clustering,Classification
- 如何在 C# 中使用 反射
- OC Swift 走马灯效果
- 疯狂乱评:UML工具
- django1.8升级1.9的几个问题
- 好玩的问答,看看你的年龄阶段哦
- 2012-11-21nbsp;09:30nbsp;NSStr…
- 定量风险分析技术__蒙特卡罗分析
- 可调稳压电源lm317实验报告_可调直流稳压电源实验报告 -
- python分号_在Python中拆分分号分隔的字符串
- 谈谈那些基础但不简单的股票数据
- 浅谈CA与证书以及Openssl管理证书
- 超星计算机技术基础 vb,程序设计技术(VB)-中国大学mooc-题库零氪
- 由IRR看超越方程求解