Android Bitmap和Drawable的對(duì)比
Android Bitmap和Drawable的對(duì)比
Bitmap - 稱作位圖,一般位圖的文件格式后綴為bmp,當(dāng)然編碼器也有很多如RGB565、RGB888。作為一種逐像素的顯示對(duì)象執(zhí)行效率高,但是缺點(diǎn)也很明顯存儲(chǔ)效率低。我們理解為一種存儲(chǔ)對(duì)象比較好。
Drawable - 作為Android平下通用的圖形對(duì)象,它可以裝載常用格式的圖像,比如GIF、PNG、JPG,當(dāng)然也支持BMP,當(dāng)然還提供一些高級(jí)的可視化對(duì)象,比如漸變、圖形等。
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規(guī)定:
Though usually not visible to the application, Drawables may take a variety of forms: 盡管通常情況下對(duì)于應(yīng)用是不可見的,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.
對(duì)比項(xiàng) | 顯示清晰度 | 支持透明色 | 支持色相色差調(diào)整 | 支持像素操作 |
---|---|---|---|---|
Bitmap | 相同 | 是 | 是 | 是 |
Drawable | 相同 | 是 | 否 | 否 |
Drawable在內(nèi)存占用和繪制速度這兩個(gè)非常關(guān)鍵的點(diǎn)上勝過Bitmap
- Drawable和Bitmap之間可以互相轉(zhuǎn)換,Drawable占用內(nèi)存遠(yuǎn)小于Bitmap。
- setImageDrawable使用資源文件;setImageBitmap使用bitmap圖片,該圖片可能是讀取本地相冊(cè),或者從資源文件轉(zhuǎn)換而來。
- 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); //占用內(nèi)存 // setImageBitmap() Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); imageView.setImageBitmap(image); // Bitmap轉(zhuǎn)換成Drawable Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); BitmapDrawable bitmapDrawable = new BitmapDrawable(image); imageView.setImageDrawable(bitmapDrawable); // 結(jié)論:Bitmap是Drawable . Drawable不一定是Bitmap
小結(jié)
Bitmap: 簡單化的Drawable, PNG 或JPEG圖像.
Drawable在內(nèi)存占用和繪制速度這兩個(gè)非常關(guān)鍵的點(diǎn)上勝過Bitmap
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Android中一種巧妙的drawable.xml替代方案分享
- Android RippleDrawable 水波紋/漣漪效果的實(shí)現(xiàn)
- Android自定義Drawable之在Drawable中部指定透明區(qū)域方法示例
- 淺談Android中Drawable使用知識(shí)總結(jié)
- Android開發(fā)基于Drawable實(shí)現(xiàn)圓角矩形的方法
- Android自定義Drawable實(shí)現(xiàn)圓角效果
- Android Drawable和Bitmap的轉(zhuǎn)換實(shí)例詳解
- Android DrawableTextView圖片文字居中顯示實(shí)例
- Android Drawable必備知識(shí)小結(jié)
- Android drawable微技巧,你不知道的drawable細(xì)節(jié)
相關(guān)文章
Java實(shí)現(xiàn)Andriod帶看括弧的計(jì)算器代碼
這篇文章主要介紹了Java實(shí)現(xiàn)Andriod帶看括弧的計(jì)算器代碼的相關(guān)資料,需要的朋友可以參考下2016-03-03Android自定義View實(shí)現(xiàn)音頻播放圓形進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)音頻播放圓形進(jìn)度條,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06一篇文章弄懂Android自定義viewgroup的相關(guān)難點(diǎn)
這篇文章主要給大家介紹了關(guān)于如何通過一篇文章弄懂Android中自定義viewgroup的一些相關(guān)難點(diǎn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06android用java和c實(shí)現(xiàn)查找sd卡掛載路徑(sd卡路徑)的方法
這篇文章主要介紹了android用java和c實(shí)現(xiàn)查找sd卡掛載路徑(sd卡路徑)的方法,需要的朋友可以參考下2014-02-02Android仿微信清理內(nèi)存圖表動(dòng)畫(解決surfaceView屏幕閃爍問題)demo實(shí)例詳解
本文通過實(shí)例代碼給大家講解android仿微信清理內(nèi)存圖表動(dòng)畫(解決surfaceView屏幕閃爍問題)的相關(guān)資料,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09為Android Studio編寫自定義Gradle插件的教程
這篇文章主要介紹了為Android Studio編寫自定義Gradle插件的教程,Android Studio現(xiàn)在基本上已經(jīng)成為了安卓開發(fā)的標(biāo)配IDE,友可以參考下2016-02-02Android控件系列之RadioButton與RadioGroup使用方法
本文介紹了Android中如何使用RadioGroup和RadioButton,對(duì)比了RadioButton和CheckBox的區(qū)別,并實(shí)現(xiàn)了自定義的RadioGroup中被選中RadioButton的變更監(jiān)聽事件2012-11-11