如何在android中创建文本路径的模式填充?

时间:2012-06-28 21:43:27

标签: android paint android-canvas

我试图通过在两个状态之间随时间改变来以编程方式生成以下效果

State-1 image State-2 image

基本上在第一个图像(状态#1)中,我想获得填充了我自己的自定义位图的文本的路径(如上例所示为红色圆圈),那些应该是在固定距离后重复(在这种情况下恰好与红色圆圈的直径相同)。 在第二个图像(状态#2)中,红色圆圈采用替代模式,它们的位置是状态#1中的空白区域。

the answer to this question收集我可以在我的画上使用BitmapShaders。以下是我为一个州提出的代码。然而,我陷入困境,无法思考如何实现这一目标。

public void drawText(String text, int x, int y) {
    Paint defPaint = new Paint();
    defPaint.setTextSize(100);
    defPaint.setStrokeWidth(0);

    defPaint.setStyle(Style.FILL_AND_STROKE);

    defPaint.setShader(new BitmapShader(
            ((AndroidPixmap) Assets.redCircle).bitmap, TileMode.REPEAT,
            TileMode.REPEAT));

    Path path = new Path();
    defPaint.getTextPath(text, 0, text.length(), x, y, path);
    canvas.drawPath(path, defPaint);
}

我也尝试使用PathEffects,但也没有成功。

0 个答案:

没有答案