Sam*_*mar 59 android paint bitmap android-canvas
我想要一个带有粗体文本的位图图标在地图上绘制它.我有一个片段在图像上写文字:
Bitmap icon = BitmapFactory.decodeResource(PropertyMapList.this.getResources(),
R.drawable.location_mark);
TextPaint paint = new TextPaint();
paint.setColor(Color.BLACK);
paint.setTextSize(14);
paint.setFakeBoldText(true);
//paint.setTextAlign(Align.CENTER);
Bitmap copy = icon.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(copy);
//canvas.drawText(jsonObj.getString("district_name"), 5, canvas.getHeight()/2, paint);
String districtName = jsonObj.getString("district_name");
StaticLayout layout = new StaticLayout((districtName.length()>25 ? districtName.substring(0, 24)+"..":districtName)+"\n"+jsonObj.getString("total_properties"), paint, canvas.getWidth()-10,Layout.Alignment.ALIGN_CENTER, 1.3f, 0, false);
canvas.translate(5, canvas.getHeight()/2); //position the text
layout.draw(canvas);
Run Code Online (Sandbox Code Playgroud)
setFakeBoldText(true)
不适合我.我希望Bitmap上绘制的文本加粗.
Gab*_*han 158
使用对象setTypeface
上的方法Paint
将字体设置为打开粗体样式的字体.
paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Run Code Online (Sandbox Code Playgroud)
对于自定义字体:
Typeface typeface = Typeface.create(Typeface.createFromAsset(mContext.getAssets(), "fonts/bangla/bensen_handwriting.ttf"), Typeface.BOLD);
Run Code Online (Sandbox Code Playgroud)
对于普通字体:
Typeface typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD);
// or
Typeface typeface = Typeface.DEFAULT_BOLD;
Run Code Online (Sandbox Code Playgroud)
进而
paint.setTypeface(typeface);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29536 次 |
最近记录: |