简体   繁体   English

如何修复模糊的自定义标记 Android google map api

[英]How to fix blurry custom marker Android google map api

I created custom marker on Android Google map api but it give a blurry image when it displayed.我在 Android 谷歌地图 api 上创建了自定义标记,但它在显示时给出了一个模糊的图像。 How do I get a better stunning custom marker and didn't give a blur in low resolution (my marker resolution is 25x26 px).我如何获得更好的令人惊叹的自定义标记并且在低分辨率下没有模糊(我的标记分辨率为 25x26 像素)。 I didn't use hight resolution image like 250x250 px because it shown a big custom marker in map.我没有使用像 250x250 像素这样的高分辨率图像,因为它在地图中显示了一个很大的自定义标记。

Your question is technically a duplicate of this question:你的问题在技术上是这个问题的重复:

Different resolution support android 不同分辨率支持android

I say technically because the information contained above is sufficient for you to answer your own question, but it is not perhaps obvious how to piece everything together.我这么说是因为上面包含的信息足以让您回答自己的问题,但如何将所有内容拼凑起来可能并不明显。 The jist of the answers is that Android provides the following drawable folders to cover the various resolutions which your app might encounter when being run on actual device.答案的要点是,Android 提供了以下可绘制文件夹来涵盖您的应用在实际设备上运行时可能遇到的各种分辨率。 Android will use the image which is appropriate to the resolution on your which app is being run. Android 将使用适合您正在运行的应用程序的分辨率的图像。 Taken from the duplicate link:取自重复链接:

res/drawable        (default)
res/drawable-ldpi/  (240x320 and nearer resolution)
res/drawable-mdpi/  (320x480 and nearer resolution)
res/drawable-hdpi/  (480x800, 540x960 and nearer resolution)
res/drawable-xhdpi/  (720x1280 - Samsung S3, Micromax Canvas HD etc)
res/drawable-xxhdpi/ (1080x1920 - Samsung S4, HTC one, Nexus 5, etc)
res/drawable-xxxhdpi/ (1440X2560 - Nexus 6,Samsung S6edge).

Suppose you have a custom Google Maps marker whose original is 100x200, ie 100 pixels wide and 200 pixels tall.假设您有一个自定义 Google 地图标记,其原始尺寸为 100x200,即 100 像素宽和 200 像素高。 This would roughly fit what many of the bundled markers look like.这大致符合许多捆绑标记的外观。 Now, suppose you want to support hdpi resolution.现在,假设您要支持hdpi分辨率。 Well, from the list above, you would then be expecting a 480x800 resolution.好吧,从上面的列表中,您会期待480x800分辨率。 Let's also say you want the custom map marker to take up 10% of the width of the screen in portrait, or 48 pixels wide.假设您希望自定义地图标记占据纵向屏幕宽度的 10%,或 48 像素宽。 Then you would make a copy of your original marker image scaled down such that the width is 48 pixels, ie it would be 48x96 pixels.然后,您将缩小原始标记图像的副本,使其宽度为 48 像素,即 48x96 像素。

Now, place this custom resized image into the drawable/hdpi folder.现在,将此自定义调整大小的图像放入drawable/hdpi文件夹中。 When Android is running on hdpi resolution, it will use this image when rendering the marker, and it should not appear blurry.当 Android 在hdpi分辨率下运行时,它会在渲染标记时使用此图像,并且它不应显得模糊。

So that the process is clear, here is the above again, but this time with the exact resolutions you can use for your custom Google Maps marker.为了使过程清晰,这里又是上述内容,但这次使用您可以用于自定义 Google 地图标记的确切分辨率。 Again, I assume that your original is 100x200.同样,我假设您的原件是 100x200。

folder                | device size | marker size
res/drawable          | (default)   | none (you don't need one here)
res/drawable-ldpi/    | 240x320     | 24x48
res/drawable-mdpi/    | 320x480     | 32x64
res/drawable-hdpi/    | 480x800     | 48x96
res/drawable-xhdpi/   | 720x1280    | 72x144
res/drawable-xxhdpi/  | 1080x1920   | 108x216
res/drawable-xxxhdpi/ | 1440X2560   | 144x288

Note that here you would actually have to stretch your image for xxhdpi and xxxhdpi .请注意,在这里您实际上必须为xxhdpixxxhdpi拉伸图像。 In this case, you might want to start with an even higher resolution image.在这种情况下,您可能希望从分辨率更高的图像开始。

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

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