当paint设置为Stroke时,Android Canvas.drawTextOnPath看起来不正确

时间:2012-02-29 04:34:16

标签: android view path stroke

我在扩展视图中设置了一些代码,它可以完成一些易于缩放(类似矢量)的绘图。 (我的比例设置为0-1.0)

我注意到当我将绘制填充设置为FILL时,路径上绘制的文本看起来是正确的,但是当我将填充设置为笔划(我只想要文本的轮廓)时,图像看起来就像是LSD之旅。这是我的示例代码:

    Paint yellowPaint = Paints.getFillTextPaint(0.01f, 0xFFffea3e, 0.065f);
    canvas.drawTextOnPath(mContext.getString(R.string.building_a_partnership),
             Paths.getRoundedTextPath(mOuterCircleRectF, 280f, 350f),
             0, -0.025f, yellowPaint);

public static Paint getFillTextPaint(float f, int color, float textSize) {
        Paint textPaint = new Paint();
        textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setColor(color);
        textPaint.setTextSize(textSize);
        textPaint.setStrokeWidth(f);
        textPaint.setShadowLayer(0.002f, 0.0f, 0.0f, 0xFF000000);
        textPaint.setTypeface(Typeface.SANS_SERIF);
        return textPaint;
    }

如果我将Paint.Style从FILL更改为STROKE,我会得到下面的图像。我使用了canvas.drawText(),它可以很好地显示描边字母。只有当它应用于Path时才会变得奇怪。

Fill Image

Stroke Image

1 个答案:

答案 0 :(得分:0)

显然这是因为我的比例因子是0-1 ..似乎有一个错误,如何渲染大小< 1.0被处理。建议的解决方案是使用0-100的等级。