日常疑問之——Android Studio中mipmap和drawable的區(qū)別
用了Android studio有一段時(shí)間了,每次新建一個(gè)工程的時(shí)候棕诵,總是先把mipmap刪掉,新建幾個(gè)不同dpi的drawable文件价脾,才開始干別的笛匙。究竟mipmap和drawable有什么區(qū)別呢妹孙?對(duì)此疑問進(jìn)行一次總結(jié),
經(jīng)過查看官方介紹和其他資料骇笔,得出結(jié)論:
mipmap文件夾下机隙,僅僅建議放啟動(dòng)圖標(biāo)(app/ launcher icons)和縮放動(dòng)畫相關(guān)的圖片,而其他的圖片資源等萨西,還是按照以前方式有鹿,放在drawable文件夾下。
下面再詳細(xì)闡述下谎脯,得出以上結(jié)論的依據(jù):
1.google官方關(guān)于mipmap和drawable的定位
mipmap的官方介紹:
Mipmapping for drawables
Usinga 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 level17) 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 Bitmap Drawable object as well, by providing a mipmap asset and setting the android:mipMap attribute in a bitmap resource file or by calling hasMipMap().
關(guān)于mipmap的使用場(chǎng)景:
If you know that you are going to draw this bitmap at less than 50% of its original size, you may be able to obtain a higher quality by turning this property on. Note that if the renderer respects this hint it might have to allocate extra memory to hold the mipmap levels for this bitmap.
如果你事先已經(jīng)知道你要顯示的圖片可能小于原圖片大小的50%葱跋,使用mipmap文件夾存儲(chǔ),會(huì)獲得一個(gè)會(huì)獲得一個(gè)更高質(zhì)量的圖片源梭。
注意:如果渲染器有參與的情況下娱俺,它可能需要分配額外的內(nèi)存才能hold住mipmap文件下的這個(gè)位圖。
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.
如果你的圖片可能要進(jìn)行一些伸縮的動(dòng)畫時(shí)废麻,使用mipmap存儲(chǔ)圖片,可以輕松的提供高質(zhì)量圖像和各種圖像尺寸烛愧。
drawable的官方介紹:
drawable For bitmap files(PNG,JPEG,or GIF),9-Patchimage files,and XML files that describe Drawable shapes or Drawable objects that contain multiple states(normal,pressed,or focused).See the Drawable resource type.
mipmap For app launcher icons.The Android system retains the resources in this folder(and density-specific folders such as mipmap-xxxhdpi)regardless of the screen resolution of the device where your app is installed.This behavior allows launcher apps to pick the best resolution icon for your app to display on the home screen.Formore information about using the mipmap folders,see Managing LauncherI consas mipmap Resources.
2.stackoverflow上關(guān)于mipmap和drawable的區(qū)別
The mipmap folders are for placing your app icons in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.
3.mipmap文件夾下的圖標(biāo)會(huì)通過Mipmap紋理技術(shù)進(jìn)行優(yōu)化油宜。關(guān)于Mipmap紋理技術(shù)的介紹。
在三維世界中,顯示一張圖的大小與攝象機(jī)的位置有關(guān),近的地方,圖片實(shí)際象素就大一些,遠(yuǎn)的地方圖片實(shí)際象素就會(huì)小一些,就要進(jìn)行一些壓縮,例如一張64*64的圖,在近處,顯示出來可能是50*50,在遠(yuǎn)處可能顯示出來是20*20.
如果只限于簡(jiǎn)單的刪掉某些像素,將會(huì)使縮小后的圖片損失很多細(xì)節(jié),圖片變得很粗糙,因此,圖形學(xué)有很多復(fù)雜的方法來處理縮小圖片的問題,使得縮小后的圖片依然清晰,然而,這些計(jì)算都會(huì)耗費(fèi)一定的時(shí)間.
Mipmap紋理技術(shù)是目前解決紋理分辨率與視點(diǎn)距離關(guān)系的最有效途徑,它會(huì)先將圖片壓縮成很多逐漸縮小的圖片,例如一張64*64的圖片,會(huì)產(chǎn)生64*64,32*32,16*16,8*8,4*4,2*2,1*1的7張圖片,當(dāng)屏幕上需要繪制像素點(diǎn)為20*20時(shí)怜姿,程序只是利用 32*32 和 16*16 這兩張圖片來計(jì)算出即將顯示為 20*20 大小的一個(gè)圖片慎冤,這比單獨(dú)利用 32*32的那張?jiān)计?jì)算出來的圖片效果要好得多,速度也更快.
參考:Mipmap紋理技術(shù)簡(jiǎn)介(http://blog.csdn.net/linber214/article/details/3342051/?spm=5176.blog7416.yqblogcon1.7.l21Y7w)