Android Bitmap和Drawable的对比
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
小结
bitmap: 简单化的drawable, png 或jpeg图像.
drawable在内存占用和绘制速度这两个非常关键的点上胜过bitmap
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
下一篇: 玩转新媒体营销的八种方式