如何修复模糊自定义标记Android谷歌地图api [英] How to fix blurry custom marker Android google map api

查看:161
本文介绍了如何修复模糊自定义标记Android谷歌地图api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android Google地图api上创建了自定义标记,但它在显示时会显示模糊的图像。我如何获得更好的令人惊叹的自定义标记,并且在低分辨率下不会模糊(我的标记分辨率为25x26像素)。我没有使用像250x250像素这样的高分辨率图像,因为它在地图上显示了一个很大的自定义标记。 解决方案

这个问题的副本:



不同分辨率支持Android



我在技术上说因为上面包含的信息足以让您回答自己的问题,但如何将所有内容拼凑在一起并不明显。答案的焦点在于Android提供了以下可绘制文件夹,以涵盖您的应用在实际设备上运行时可能遇到的各种分辨率。 Android将使用适合您的应用程序正在运行的分辨率的图像。取自复制链接:

  res / drawable(默认)
res / drawable-ldpi /(240x320 and neararer分辨率)
res / drawable-mdpi /(320x480和更接近分辨率)
res / drawable-hdpi /(480x800,540x960和更接近分辨率)
res / drawable-xhdpi /(720x1280 - Samsung S3,Micromax Canvas HD等)
res / drawable-xxhdpi /(1080x1920 - Samsung S4,HTC one,Nexus 5等)
res / drawable-xxxhdpi /(1440X2560 - Nexus 6,Samsung S6edge) 。

假设您有一个自定义Google地图标记,其原始尺寸为100x200,即100像素宽,200像素高。这将大致适合许多捆绑标记的样子。现在,假设您要支持 hdpi 分辨率。那么,从上面的列表中,您将会预计 480x800 分辨率。我们还要说,您希望自定义地图标记占用屏幕宽度的10%,或者宽度为48像素。然后,您将缩放原始标记图像的副本,使其宽度为48像素,即它将为48x96像素。

现在,将此自定义大小调整的图像到 drawable / hdpi 文件夹中。当Android在 hdpi 分辨率上运行时,它在渲染标记时将使用此图像,并且不应该显示模糊。



为使过程清晰起见,以上是上述内容,但是这次可以使用您的自定义Google地图标记的确切分辨率。再次,我假设您的原始尺寸是100x200。

 文件夹|设备大小|标记大小
res / drawable | (默认)|没有(你不需要在这里)
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

请注意,在这里您实际上必须将图像拉伸至 xxhdpi xxxhdpi 。在这种情况下,您可能需要从更高分辨率的图像开始。


I created custom marker on Android Google map api but it give a blurry image when it displayed. How do I get a better stunning custom marker and didn't give a blur in low resolution (my marker resolution is 25x26 px). I didn't use hight resolution image like 250x250 px because it shown a big custom marker in map.

解决方案

Your question is technically a duplicate of this question:

Different resolution support 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 will use the image which is appropriate to the resolution on your which app is being run. 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, i.e. 100 pixels wide and 200 pixels tall. This would roughly fit what many of the bundled markers look like. Now, suppose you want to support hdpi resolution. Well, from the list above, you would then be expecting a 480x800 resolution. 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. Then you would make a copy of your original marker image scaled down such that the width is 48 pixels, i.e. it would be 48x96 pixels.

Now, place this custom resized image into the drawable/hdpi folder. When Android is running on hdpi resolution, it will use this image when rendering the marker, and it should not appear blurry.

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. Again, I assume that your original is 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. In this case, you might want to start with an even higher resolution image.

这篇关于如何修复模糊自定义标记Android谷歌地图api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆