gpt4 book ai didi

android - 如何在谷歌地图 v2 的默认标记中绘制文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:07 25 4
gpt4 key购买 nike

我想在 Google map v2 的默认标记中绘制文本。我通过从可绘制对象中获取自己的图像来完成此操作,但如何在默认标记中更改它。

我的代码是

 marker.icon(BitmapDescriptorFactory
.fromBitmap(drawTextToBitmap(getApplicationContext(), R.drawable.images,"5")));

drawTextToBitmap方法是。

public static Bitmap drawTextToBitmap(Context gContext,int gResId,String gText) {
Resources resources = gContext.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap bitmap =
BitmapFactory.decodeResource(resources, gResId);

android.graphics.Bitmap.Config bitmapConfig =
bitmap.getConfig();
if(bitmapConfig == null) {
bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
}
bitmap = bitmap.copy(bitmapConfig, true);

Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.BLACK);
paint.setTextSize((int) (15 * scale));
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

Rect bounds = new Rect();
paint.getTextBounds(gText, 0, gText.length(), bounds);
int x = (bitmap.getWidth() - bounds.width())/2;
int y = (bitmap.getHeight() + bounds.height())/2;

canvas.drawText(gText, x * scale, y * scale, paint);

return bitmap;
}

我想画那样的文字

enter image description here

最佳答案

1.下载库

github.com/googlemaps/android-maps-utils

2.要使用检查此链接

Using android-maps-utils with ADT

  TextIconGenerator tc = new TextIconGenerator(this);
Bitmap bmp = tc.makeIcon("hello");

然后将位图设置为贴图对象

  .icon(BitmapDescriptorFactory.fromBitmap(bmp))); 

快照

enter image description here

关于android - 如何在谷歌地图 v2 的默认标记中绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18335642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com