Loading...

Friday, 10 August 2012

Draw Rectangle (Android)

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.os.Bundle;
import android.widget.ImageView;

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

    // Draw Rectangle

    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(10);
   
    float left = 20;
    float top = 20;
    float right = 50;
    float bottom = 100;
   
    canvas.drawRect(left, top, right, bottom, paint);

  }
}

No comments:

Post a Comment