1. 程式人生 > >mipmap 和 drawable 的區別

mipmap 和 drawable 的區別

Android 在 API level 17 加入了 mipmap 技術,對 bitmap 圖片的渲染支援 mipmap 技術,來提高渲染的速度和質量。
android 中的 mipmap 技術主要為了應對圖片大小縮放的處理,在android 中我們提供一個 bitmap 圖片,由於應用的需要(比如縮放動畫),可能對這個 bitmap 進行各種比例的縮小,為了提高縮小的速度和圖片的質量,android 通過 mipmap 技術提前對按縮小層級生成圖片預先儲存在記憶體中,這樣就提高了圖片渲染的速度和質量。


api 中通過 Bitmap 的 public final void setHasMipMap (boolean hasMipMap) 方法可以讓系統渲染器嘗試開啟 Bitmap 的 mipmap 技術。但是這個方法只能建議系統開啟這個功能,至於是否正真開啟,還是由系統決定。


res 目錄下面 mipmap 和 drawable 的區別也就是上面這個設定是否開啟的區別。mipmap 目錄下的圖片預設 setHasMipMap 為 true,drawable 預設 setHasMipMap 為 false。


google 建議大家只把 app 的啟動圖示放在 mipmap 目錄中,其他圖片資源仍然放在 drawable 下面。


英文描述:Mipmapping for drawables
Using a mipmap as the source for your bitmap or drawable is a simple way to provide a quality image and various image scales, which can be particularly useful 
if you expect your image to be scaled during an animation.
Android 4.2 (API level 17) added support for mipmaps in the Bitmap class—Android swaps the mip images in your Bitmap
 when you’ve supplied a mipmap source and have enabled setHasMipMap(). Now in Android 4.3, you can enable mipmaps for a BitmapDrawable object as well, 
by providing a mipmap asset and setting the android:mipMap attribute in a bitmap resource file or by calling hasMipMap().




使用上沒有任何區別,你把它當drawable用就好了。


但是用mipmap系統會在縮放上提供一定的效能優化。
可參考  :參考:
android reference bitmap