Loading

Thursday, August 25, 2011

drawPath() on Canvas

drawPath() on Canvas

package com.exercise.AndroidDraw;



import android.app.Activity;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Path;

import android.os.Bundle;

import android.view.View;



public class AndroidDrawActivity extends Activity {



/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(new MyView(this));

}



public class MyView extends View {



class Pt{

float x, y;



Pt(float _x, float _y){

x = _x;

y = _y;

}

}



Pt[] myPath = { new Pt(100, 100),

new Pt(200, 200),

new Pt(200, 500),

new Pt(400, 500),

new Pt(400, 200)

};



public MyView(Context context) {

super(context);

// TODO Auto-generated constructor stub

}



@Override

protected void onDraw(Canvas canvas) {

// TODO Auto-generated method stub

super.onDraw(canvas);





Paint paint = new Paint();

paint.setColor(Color.WHITE);

paint.setStrokeWidth(3);

paint.setStyle(Paint.Style.STROKE);

Path path = new Path();



path.moveTo(myPath[0].x, myPath[0].y);

for (int i = 1; i < myPath.length; i++){

path.lineTo(myPath[i].x, myPath[i].y);

}

canvas.drawPath(path, paint);



}



}

}

SHARE TWEET

Thank you for reading this article drawPath() on Canvas With URL http://x-tutorials.blogspot.com/2011/08/drawpath-on-canvas.html. Also a time to read the other articles.

0 comments:

Write your comment for this article drawPath() on Canvas above!