본문 바로가기

#31 Image Processing-Draw Text on a Curve

http://xjaphx.wordpress.com/learning/tutorials/


Just watching on StackOverflow and found this interesting question: How to write curve text?

Here what I’ve tried so far:



Drawing Text on a Curve

Here my implementation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package pete.android.study;
 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
 
import android.graphics.RectF;
import android.view.View;
 
public class GraphicsView extends View {
    private static final String MY_TEXT = "xjaphx: Draw Text on Curve";
    private Path mArc;
 
    private Paint mPaintText;
 
    public GraphicsView(Context context) {
      super(context);
 
      mArc = new Path();
      RectF oval = new RectF(50,100,200,250);;
      mArc.addArc(oval, -180, 200);
      mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
      mPaintText.setStyle(Paint.Style.FILL_AND_STROKE);
      mPaintText.setColor(Color.WHITE);
      mPaintText.setTextSize(20f);
 
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawTextOnPath(MY_TEXT, mArc, 0, 20, mPaintText);
      invalidate();
    }
  }

Enjoy painting Android :)

Cheers,
Pete Houston