본문 바로가기

Android

그리기 객체 - Path

package com.example.viewex01;

 

import android.content.Context;

 

 

 

 

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Path;

import android.graphics.RectF;

import android.graphics.Typeface;

import android.view.View;

 

public class MyView12 extends View {

    

    

     public MyView12(Context context) {

           super(context);

           // TODO Auto-generated constructor stub

          

          

     }

 

     @Override

     public void onDraw(Canvas canvas) {

           canvas.drawColor(Color.LTGRAY);

           Path path= new Path();

           Paint Pnt= new Paint();

           Pnt.setStrokeWidth(5);

           Pnt.setColor(Color.RED);

           Pnt.setStyle(Paint.Style.STROKE);

           // , 사각형을패스로정의한후출력

           path.addCircle(50, 50, 40, Path.Direction.CW);

           path.addRect(100,10,150,90,Path.Direction.CW);

           canvas.drawPath(path, Pnt);

           // 직선곡선을패스로정의한후출력

           path.reset();

           path.moveTo(10, 110);

           path.lineTo(50, 150);

           path.rLineTo(50, -30);

           path.quadTo(120, 170, 200, 110);

           Pnt.setStrokeWidth(3);

           Pnt.setColor(Color.BLUE);

           canvas.drawPath(path, Pnt);

           // 곡선패스출력

           path.reset();

           path.moveTo(10, 220);

           path.cubicTo(80, 150, 150, 220, 220, 180);

           Pnt.setStrokeWidth(2);

           Pnt.setColor(Color.BLACK);

           canvas.drawPath(path, Pnt);

           // 곡선패스위에텍스트출력

           Pnt.setTextSize(20);

           Pnt.setStyle(Paint.Style.FILL);

           Pnt.setAntiAlias(true);

           canvas.drawTextOnPath("Curved Text on Path.", path, 0, 0, Pnt);

           }

 

}