![Draw a bitmap on View Draw a bitmap on View](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpjLHyR3B2grSi4cjzSY4BrlRM9oggC7w5Y-y-X7kOOrIuAR3KCSFKwSnLGqkNc6dLqmWHjcLBv4bAu8WQ6G3Y8QCrkvLLd-fhmQEMpDuZ237u2voo8rnCn0RDTLHqf2rNDcZUktlGMDI0/s400/AndroidPaint_01.png)
To make it simple, a bitmap of 320x480 (the size of HVGA) was prepared. It's in /res/drawable/ folder, and will be loaded using the following codes:
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.googlelogo320x480);
canvas.drawBitmap(myBitmap, 0, 0, null);
package com.exercise.AndroidPaint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;
public class AndroidPaint extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setContentView(new myView(this));
}
private class myView extends View{
public myView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.googlelogo320x480);
canvas.drawBitmap(myBitmap, 0, 0, null);
}
}
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxnVJLRg-1fv9XoJt9V-1FVRoBKEN43-Cqq5Z5wv-fMJCcKuDAAjOIdEyydLtm-nUyF07avEgyW98wSTezvppWU0IlEmIiGofqbtSqPhslO9RctZKks8OiD434Fy3uZlDdDtwCjfEr1XUT/s200/icons_download.gif)
Next: Draw something on a Canvas.