Drawable和Bitmap区别
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
1)Drawable和Bitmap之间可以互相转换。Drawable占用内存远小于Bitmap。
(2)setImageDrawable使用资源文件;setImageBitmap使用bitmap图片,该图片可能是读取本地相册,或者从资源文件转换而来。
(3) public void setImageResource (int resId)占用UI thread;
ImageView iv;
String fileName = "/data/data/com.test/aa.png;
Bitmap bm = BitmapFactory.decodeFile(fileName);
iv.setImageBitmap(bm); //占用内存,ie:
Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(image);
Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
BitmapDrawable bitmapDrawable = new BitmapDrawable(image);
imageView.setImageDrawable(bitmapDrawable);
Drawable和Bitmap区别的更多相关文章
- Android Drawable和Bitmap区别
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- Drawable与Bitmap 自定义
Drawable简介 Drawable是Android平下通用的图形对象,它可以装载常用格式的图像,比如GIF.PNG.JPG,当然也支持BMP.相比于View,我们并不需要去考虑如何measure. ...
- Android Drawable、Bitmap、byte[]之间的转换
转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...
- 获取应用图标,Drawable 转bitmap
获取应用图标: PackageManager p = context.getPackageManager(); Drawable draw=null; ApplicationInfo info; tr ...
- 简单谈谈Resource,Drawable和Bitmap之间的转换
一直接触这些东西,还是归个类整理一下比较好. Resource -> Drawable Drawable draw1 = this.getResources().getDrawable(R.dr ...
- android 获取资源文件 r.drawable中的图片转换为drawable、bitmap
1.R-Drawable Resources resources = mContext.getResources(); Drawable drawable = resources.getDrawabl ...
- Android -- Drawable与Bitmap测试
Drawable 以下这个是测试加载10 ...
- Drawable和Bitmap转换
一.Bitmap转Drawable Bitmap mBitMap=getYourBitMap(); //getYourBitMap()是你获取BitMap的方法 BitmapDrawable mBit ...
- Drawable、Bitmap、byte[]之间的转换
android在处理一写图片资源的时候,会进行一些类型的转换: 1 Drawable → Bitmap 的简单方法 ((BitmapDrawable)res.getDrawable(R.drawabl ...
随机推荐
- Sharepoint + Office Infopart + Quick Apps for Sharepoint搭建无纸化工作平台
项目背景: 某大型外企各分部通过互联网专线统一域环境,Exchange邮件系统,Sharepoint平台及依赖环境已经购买并搭建起来,Dell Quick app for Sharepoint已购卖并 ...
- Android 进程常驻(使用第三方MarsDaemon)(虽然不可用,但是还是保留下。)
github地址: https://github.com/Marswin/MarsDaemon 原理分析: Android 进程常驻(0)----MarsDaemon使用说明 Android 进程常驻 ...
- linux install StarDict
1. sudo apt-get install stardict 2. Downloads from: http://abloz.com/huzheng/stardict-dic/zh_CN/ 3. ...
- 【Telerik】<telerik:RadGridView/>控件的使用
学习Telerik第三方控件中的WPF时,对于RadGridView控件做的一些记录. AutoGenerateColumns:启动时是否生成列 ShowGroupPanel:是否显示表格的分组名称 ...
- Neil·Zou 语录三
1 人的大脑,假设100分成熟.那么每个人大脑达到100分的时间点不同.有些人因为外界因素在读书时就达到了,而有些人到工作后才达到.但很可惜,很多国人进入社会后就不学习了.所以说,工作后保持激情.好奇 ...
- 使用 PHP 内置函数 get_browser() 判断是否是移动浏览器
get_browser — 获取浏览器具有的功能.该函数通过查找 browscap.ini 文件中的浏览器信息,尝试检测用户的浏览器所具有的功能. 由于许可证的问题,PHP 未提供浏览器功能文件,可以 ...
- GET,POST — 简述
本文主要对GET与POST基本区别进行汇总并掌握,如有错误与遗漏之处,请指出. 文章出处:http://www.cnblogs.com/useryangtao/ 1. HTTP HTTP(即超文本传输 ...
- 常用数据库的驱动程序及JDBC URL:
Oracle数据库: 驱动程序包名:ojdbc14.jar 驱动类的名字:oracle.jdbc.driver.OracleDriver JDBC URL:jdbc:oracle:thin:@dbip ...
- ASP.NET Web API 2基于令牌的身份验证
基于令牌的认证 我们知道WEB网站的身份验证一般通过session或者cookie完成的,登录成功后客户端发送的任何请求都带上cookie,服务端根据客户端发送来的cookie来识别用户. WEB A ...
- ESXi 5.5开启并配置SNMP
1. 安装vshpere cli 2.设定SNMP通讯字并开启SNMP功能 进入到bin目录. C:\Program Files (x86)\VMware\VMware vSphere CLI\bin ...