Drawable和Bitmap區別

來源:互聯網
上載者:User

標籤:android   io   ar   os   使用   sp   for   檔案   on   

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區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.