可拉伸转换为位图改变谷歌地图API的Andr​​oid V2标记的颜色 [英] Converting a Drawable to a Bitmap to change the color of a Marker in Google Maps Android API v2

查看:178
本文介绍了可拉伸转换为位图改变谷歌地图API的Andr​​oid V2标记的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从V1至V2转换旧应用程序,而我在与我的标记图标的颜色有问题。我有一个基本的,白色的图标,它需要进行着色。

I'm converting an old application from v1 to v2, and I'm having a problem with the color of my Marker icons. I have a basic, white icon, and It needs to be colorized.

在V1,我这样做的:

Drawable d = DrawableUtils.resizeImageToDrawable(
    MapViewFragment.mapviewActivity,
    Configuration.Display.getDrawableFix(i),
    Configuration.MapView.getWaypointIconWidth(),
    Configuration.MapView.getWaypointIconHeight());
d.setColorFilter(color, Mode.MULTIPLY);

overlay = new MyFplnFixListItimizedOverlay(d);

由于V2标记不接受可绘制他们的图标,我想到了绘制对象转换为位图,像这样的:

Since v2 Markers do not accept Drawables for their icons, I thought about converting the Drawable to a Bitmap, like this :

Drawable d = DrawableUtils.resizeImageToDrawable(
    MapViewFragment.mapviewActivity,
    Configuration.Display.getDrawableFix(i),
    Configuration.MapView.getWaypointIconWidth(),
    Configuration.MapView.getWaypointIconHeight());
d.setColorFilter(color, Mode.MULTIPLY);

Bitmap icon = ((BitmapDrawable) d).getBitmap();

Marker marker = MapViewFragment.map.addMarker(new MarkerOptions()
    .position(point)
    .title(Integer.toString(fplnType))
    .visible(true)
    .icon(BitmapDescriptorFactory.fromBitmap(icon)));

但由于某些原因,它不工作。图标留白。任何人都知道这是为什么?

But for some reason, it's not working. The icons stay white. Anyone knows why ?

先谢谢了。

推荐答案

确定,这里就是我做了它在一天的末尾:

OK, here's how I did it at the end of the day :

Drawable d = DrawableUtils.resizeImageToDrawable(
                    MapViewFragment.mapViewActivity,
                    Configuration.Display.getDrawableFix(i),
                    Configuration.MapView.getWaypointIconWidth(),
                    Configuration.MapView.getWaypointIconHeight());
d.setColorFilter(color, Mode.MULTIPLY);

Bitmap b = ((BitmapDrawable) d).getBitmap();
Canvas myCanvas = new Canvas(b);

int myColor = b.getPixel(0,0);
ColorFilter filter = new LightingColorFilter(myColor, color);

Paint pnt = new Paint();
pnt.setColorFilter(filter);
myCanvas.drawBitmap(b,0,0,pnt);

Marker marker = MapViewFragment.map.addMarker(new MarkerOptions()
    .position(point)
    .title(Integer.toString(fplnType))
    .visible(true)
    .icon(BitmapDescriptorFactory.fromBitmap(b)));

这篇关于可拉伸转换为位图改变谷歌地图API的Andr​​oid V2标记的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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