Friday, September 7, 2012

Draw bitmap on canvas

Modify onDraw(Canvas canvas) method of in the former exercise to draw bitmap on convas of our custom view.

 protected void onDraw(Canvas canvas) {

  float w, h, cx, cy;
  w = getWidth();
  h = getHeight();
  cx = w/2;
  cy = h/2;

  canvas.drawRect(0, 0, w, h, BackPaint);
  Bitmap myBitmap = BitmapFactory.decodeResource(
        canvas.drawBitmap(myBitmap, cx, cy, null);

Draw bitmap on canvas

download filesDownload the files.

No comments: