简体   繁体   English

我如何从高分辨率图像android获取所有dpi图像

[英]how can i get all dpi images from high resolution image android

I'am a new android developer. 我是一个新的Android开发人员。

Our designer gave me some high resolution images for my app, but I known there are many devices (different screens) that support the android platform. 我们的设计师为我的应用程序提供了一些高分辨率图像,但我知道有许多设备(不同的屏幕)支持Android平台。

My question is. 我的问题是。 How can I get all the dpi(hdpi-mdpi-ldpi-xx) resources from the high resolution images? 如何从高分辨率图像中获取所有dpi(hdpi-mdpi-ldpi-xx)资源?

如果我得到你的问题,这里是解决方案:) http://coh.io/adpi/

Just add all your images on the xhdpi folder and Android will find them recursively through the folders until it found the requested photo independently from from the devices screen density. 只需在xhdpi文件夹中添加所有图像,Android就会通过文件夹递归地找到它们,直到它从设备屏幕密度中独立地找到所请求的照片。

From the documentation: 从文档:

At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource: 在运行时,系统确保在当前屏幕上以最佳方式显示任何给定资源的以下过程:

  1. The system uses the appropriate alternative resource Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. 系统使用适当的替代资源根据当​​前屏幕的大小和密度,系统使用应用程序中提供的任何特定于大小和密度的资源。 For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. 例如,如果设备具有高密度屏幕并且应用程序请求可绘制资源,则系统会查找与设备配置最匹配的可绘制资源目录。 Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory. 根据可用的其他备用资源,具有hdpi限定符的资源目录(例如drawable-hdpi /)可能是最佳匹配,因此系统使用此目录中的可绘制资源。

  2. If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density The "default" resources are those that are not tagged with a configuration qualifier. 如果没有可用的匹配资源,系统将使用默认资源并根据需要向上或向下扩展以匹配当前屏幕大小和密度“默认”资源是未使用配置限定符标记的资源。 For example, the resources in drawable/ are the default drawable resources. 例如,drawable /中的资源是默认的可绘制资源。 The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. 系统假定默认资源是针对基线屏幕尺寸和密度设计的,这是正常的屏幕尺寸和中等密度。 As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate. 因此,系统会根据需要为高密度屏幕缩放默认密度资源,为低密度屏幕缩小默认密度资源。 However, when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. 但是,当系统查找特定于密度的资源但未在密度特定的目录中找到它时,它将不会始终使用默认资源。 The system may instead use one of the other density-specific resources in order to provide better results when scaling. 系统可以改为使用其他密度特定资源中的一个,以便在缩放时提供更好的结果。 For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75. 例如,当寻找低密度资源并且它不可用时,系统倾向于缩小资源的高密度版本,因为系统可以轻松地将高密度资源缩放到低密度资源。与将中密度资源缩放0.75倍相比,因子为0.5,伪影更少。 For more information about how Android selects alternative resources by matching configuration qualifiers to the device configuration, read How Android Finds the Best-matching Resource. 有关Android如何通过将配置限定符与设备配置相匹配来选择备用资源的更多信息,请阅读Android如何查找最匹配的资源。

Either way for getting the other resources if you want to follow good practices, this are the ratios to scale your hdpi resources to lower densities. 无论哪种方式获得其他资源,如果您想遵循良好实践,这是将您的hdpi资源扩展到较低密度的比率。

在此输入图像描述

Hope it helps :) 希望能帮助到你 :)

you can convert them and create the appropriate images for each resolution using the link @karvoynistas posted and this would also be a must read. 您可以使用@karvoynistas发布的链接转换它们并为每个分辨率创建适当的图像, 这也是必读的。

Notice that you don't really need to do anything if you want to let your images being resized automatically... (you can define only one folder and let the system resize them. Pros: your app would weight less. Cons: it may be slower and you may have problems of memory with large images due to a limited heap size...) 请注意,如果您想让图像自动调整大小,您根本不需要做任何事情......(您只能定义一个文件夹并让系统调整它们的大小。优点:您的应用程序会减轻重量。缺点:它可能由于堆大小有限,你可能会因为大图像而出现内存问题......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM