Android Studio中mipmap和drawable文件夹的区别

日常疑问之——Android Studio中mipmap和drawable的区别

用了Android studio有一段时间了,每次新建一个工程的时候,总是先把mipmap删掉,新建几个不同dpi的drawable文件,才开始干别的。究竟mipmap和drawable有什么区别呢?对此疑问进行一次总结,

经过查看官方介绍和其他资料,得出结论:

mipmap文件夹下,仅仅建议放启动图标(app/ launcher icons)和缩放动画相关的图片,而其他的图片资源等,还是按照以前方式,放在drawable文件夹下。

下面再详细阐述下,得出以上结论的依据:

1.google官方关于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().

关于mipmap的使用场景:

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.

如果你事先已经知道你要显示的图片可能小于原图片大小的50%,使用mipmap文件夹存储,会获得一个会获得一个更高质量的图片。

注意:如果渲染器有参与的情况下,它可能需要分配额外的内存才能hold住mipmap文件下的这个位图。

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.

如果你的图片可能要进行一些伸缩的动画时,使用mipmap存储图片,可以轻松的提供高质量图像和各种图像尺寸。

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上关于mipmap和drawable的区别

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文件夹下的图标会通过Mipmap纹理技术进行优化。关于Mipmap纹理技术的介绍。

在三维世界中,显示一张图的大小与摄象机的位置有关,近的地方,图片实际象素就大一些,远的地方图片实际象素就会小一些,就要进行一些压缩,例如一张64*64的图,在近处,显示出来可能是50*50,在远处可能显示出来是20*20.

如果只限于简单的删掉某些像素,将会使缩小后的图片损失很多细节,图片变得很粗糙,因此,图形学有很多复杂的方法来处理缩小图片的问题,使得缩小后的图片依然清晰,然而,这些计算都会耗费一定的时间.

Mipmap纹理技术是目前解决纹理分辨率与视点距离关系的最有效途径,它会先将图片压缩成很多逐渐缩小的图片,例如一张64*64的图片,会产生64*64,32*32,16*16,8*8,4*4,2*2,1*1的7张图片,当屏幕上需要绘制像素点为20*20时,程序只是利用 32*32 和 16*16 这两张图片来计算出即将显示为 20*20 大小的一个图片,这比单独利用 32*32的那张原始片计算出来的图片效果要好得多,速度也更快.

参考:Mipmap纹理技术简介(http://blog.csdn.net/linber214/article/details/3342051/?spm=5176.blog7416.yqblogcon1.7.l21Y7w)

你可能感兴趣的:(Android Studio中mipmap和drawable文件夹的区别)