我想为我的Google地图着色图标。这是我的代码-
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_location));
我该如何着色想要的颜色?目前,可绘制对象为绿色。
最佳答案
您可以轻松地做到这一点,可以将可绘制图像设置在可绘制文件夹中。这不是色彩,但这是最好的解决方案。
itmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.yourdrawable)
MarkerOptions markerOptions = new MarkerOptions().position(latLng)
.title("Current Location")
.snippet("Thinking of finding some thing...")
.icon(icon);
mMarker = googleMap.addMarker(markerOptions);
更新资料
您可以使用它来更改位图的颜色
private Bitmap changeBitmapColor(Bitmap sourceBitmap, int color) {
Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);
Paint p = new Paint();
ColorFilter filter = new LightingColorFilter(color, 1);
p.setColorFilter(filter);
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(resultBitmap, 0, 0, p);
return resultBitmap;
}
有关使用位图
BitmapDescriptorFactory.fromBitmap
的信息,请告诉我是否可以解决您的问题。