日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android bitmap对比,Android Bitmap和Drawable的对比

發布時間:2025/3/15 Android 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android bitmap对比,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

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

總結

如果覺得編程之家網站內容還不錯,歡迎將編程之家網站推薦給程序員好友。

本圖文內容來源于網友網絡收集整理提供,作為學習參考使用,版權屬于原作者。

小編個人微信號 jb51ccc

喜歡與人分享編程技術與工作經驗,歡迎加入編程之家官方交流群!

總結

以上是生活随笔為你收集整理的android bitmap对比,Android Bitmap和Drawable的对比的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。