与WINGDING.ttf字体画布绘制文本不工作在Android [英] Drawing text on canvas with WINGDING.ttf font is not working on android
本文介绍了与WINGDING.ttf字体画布绘制文本不工作在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我绘制文字与自定义的字体(基本上图标例如:WINGDING.ttf)使用的drawText是显示为提供简单的文字
When I am drawing Text with custom font(basically icon ex: WINGDING.ttf) using drawText is showing simple text as provided.
我的步骤如下:
1.添加字体文件夹资产
2.将涂料与添加的字体
3.绘制文本与涂料
Steps I followed: 1. Added font file to Assets folder 2. Set paint with the added font 3. drawing text with the paint
要绘制文本我用相应的英文字符
To draw text I used the corresponding English character
canvas.drawText("p",0,1, x, y, myPaint);
这显示作为应用P
推荐答案
如果你有资产/字体,用这样的方式:
use this way if you have assets/fonts:
private Paint myPaint= new Paint(Paint.ANTI_ALIAS_FLAG);
private Typeface mFace;
mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/WINGDING.ttf");
myPaint.setTextSize(32);
myPaint.setTypeface(mFace);
canvas.drawText("test test",0,1, x, y, myPaint);
//canvas.drawText("test test", 10, 200, myPaint);
例如:
private static class MyView extends View
{
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Typeface mFace;
public MyView(Context context)
{
super(context);
mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/WINGDING.ttf");
mPaint.setTextSize(32);
}
@Override protected void onDraw(Canvas canvas)
{
mPaint.setTypeface(mFace);
canvas.drawText("p p p p", 10, 200, mPaint);
}
}
这篇关于与WINGDING.ttf字体画布绘制文本不工作在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文