国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android Bitmap和Drawable的對比

2019-12-12 02:46:52
字體:
來源:轉載
供稿:網友

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轉換成DrawableBitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());BitmapDrawable bitmapDrawable = new BitmapDrawable(image);imageView.setImageDrawable(bitmapDrawable);// 結論:Bitmap是Drawable . Drawable不一定是Bitmap

小結

Bitmap: 簡單化的Drawable, PNG 或JPEG圖像. 

Drawable在內存占用和繪制速度這兩個非常關鍵的點上勝過Bitmap

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 军事| 高雄市| 新化县| 桃园县| 昌图县| 长兴县| 紫阳县| 成都市| 铜梁县| 贺兰县| 祁东县| 原平市| 盈江县| 九江市| 沙雅县| 井冈山市| 泸西县| 靖州| 武鸣县| 胶州市| 奈曼旗| 盘山县| 徐州市| 和田县| 农安县| 阿瓦提县| 庄河市| 昆明市| 泰宁县| 通渭县| 本溪市| 临城县| 新昌县| 丰宁| 格尔木市| 定安县| 饶平县| 江都市| 武鸣县| 正安县| 磴口县|