Draw path : Path « 2D Graphics « Android






Draw path

 

package app.test;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.widget.ImageView;

public class Test extends Activity {
  ImageView drawingImageView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    drawingImageView = (ImageView) this.findViewById(R.id.DrawingImageView);
    Bitmap bitmap = Bitmap.createBitmap((int) getWindowManager()
        .getDefaultDisplay().getWidth(), (int) getWindowManager()
        .getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawingImageView.setImageBitmap(bitmap);

    // Path

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.GREEN);
    Path p = new Path();
    p.moveTo(20, 20);
    p.lineTo(100, 200);
    p.lineTo(200, 100);
    p.lineTo(240, 155);
    p.lineTo(250, 175);
    p.lineTo(20, 20);
    canvas.drawPath(p, paint);

  }
}

   
  








Related examples in the same category

1.Draw text along with path
2.Create a Path
3.Using PathEffect
4.Path Effects
5.Path Fill Types