您的位置:首页 > 移动开发 > Android开发

Arcgis for Android解决标注TextSymbol中文字体乱码的问题

2017-12-01 08:52 801 查看
/**
* @作者 Author
* @创建日期 2017/12/1 0001
* @创建时间 上午 8:39
* @描述 —— 将android的文字转换为底图透明的图片
*/
public static Bitmap creatCodeBitmap(String contents, Context context) {
float scale = context.getResources().getDisplayMetrics().scaledDensity;

TextView tv = new TextView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(layoutParams);
tv.setText(contents);
tv.setTextSize(scale * 8);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setDrawingCacheEnabled(true);
tv.setTextColor(Color.RED);
tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

//tv.setBackgroundColor(Color.GREEN);

tv.buildDrawingCache();
Bitmap bitmapCode = tv.getDrawingCache();
return bitmapCode;
}

// 将bitmap转换为Drawable资源
Bitmap bitmap = creatCodeBitmap(bz,context);
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol(drawable);
labelGraphicsLayer.addGraphic(new Graphic(point, pictureMarkerSymbol));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息