Boj*_*ski 4 android google-maps google-maps-markers android-drawable android-maps-v2
是否可以在Google Maps API v2中设置自定义彩色标记?我有一个白色的可绘制资源,我想对它应用彩色滤镜.我试过这个:
String color = db.getCategoryColor(e.getCategoryId());
Drawable mDrawable = this.getResources().getDrawable(R.drawable.event_location);
mDrawable.setColorFilter(Color.parseColor(Model.parseColor(color)),Mode.SRC_ATOP);
map.addMarker(new MarkerOptions().position(eventLocation)
.title(e.getName()).snippet(e.getLocation())
.icon(BitmapDescriptorFactory.fromBitmap(((BitmapDrawable) mDrawable).getBitmap())));
Run Code Online (Sandbox Code Playgroud)
但它不起作用.它仅显示没有自定义颜色的白色标记.我传递给setColorFilter()的"颜色"字符串的值是"#RRGGBB"的形式.
Boj*_*ski 15
我在这里给出了答案:https://groups.google.com/forum/#!topic/installer -developers/KLaDMMxSkLs您应用于Drawable的ColorFilter不会直接应用于Bitmap,它应用于Paint用于渲染位图.所以修改后的工作代码如下所示:
String color = db.getCategoryColor(e.getCategoryId());
Bitmap ob = BitmapFactory.decodeResource(this.getResources(),R.drawable.event_location);
Bitmap obm = Bitmap.createBitmap(ob.getWidth(), ob.getHeight(), ob.getConfig());
Canvas canvas = new Canvas(obm);
Paint paint = new Paint();
paint.setColorFilter(new PorterDuffColorFilter(Color.parseColor(Model.parseColor(color)),PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(ob, 0f, 0f, paint);
Run Code Online (Sandbox Code Playgroud)
...现在我们可以添加obm作为彩色地图标记:
map.addMarker(new MarkerOptions().position(eventLocation)
.title(e.getName()).snippet(e.getLocation())
.icon(BitmapDescriptorFactory.fromBitmap(obm)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3783 次 |
| 最近记录: |