作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想在 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;
}
我想画那样的文字
最佳答案
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)));
快照
关于android - 如何在谷歌地图 v2 的默认标记中绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18335642/
我是一名优秀的程序员,十分优秀!