This is a really basic thing, but it's just took me hours to work out how to do, and Google said nothing useful at all on the matter. So, I'm posting this just so that next time someone googles it, they have a quick response.
How to draw an image in Android
1. Save an image, such as a .png, in the folder myGame/res/drawable-mdpi
2. Eclipse will load this and assign a variable to it that you can use
Then:
In your draw method of your class:
Where g is your canvas.
Here, "background1" is the name of your image.
You'll need a Context. Everyone will throw around the word Context without giving you a clue in hell as to what it means.
Well, Activity is a Context. So, you'll need to pass "this" in when initializing your class in your activity.
For example:
Anyway I hope it's useful.
And I can guarantee that magically as soon as I've posted this somebody will reply and say "that's simple! You actually only need to x, y, z"
Such is the way of bloody java programming.
I'm on a horse.
How to draw an image in Android
1. Save an image, such as a .png, in the folder myGame/res/drawable-mdpi
2. Eclipse will load this and assign a variable to it that you can use
Then:
import android.graphics.BitmapFactory;
In your draw method of your class:
g.drawBitmap(BitmapFactory.decodeResource(activity.getResources(), R.drawable.background1), 0, 0, null);
Where g is your canvas.
Here, "background1" is the name of your image.
You'll need a Context. Everyone will throw around the word Context without giving you a clue in hell as to what it means.
Well, Activity is a Context. So, you'll need to pass "this" in when initializing your class in your activity.
For example:
Background background = new Background(width, height, this);
// in your class
public Background(int width, int height, Activity a)
{
activity = a;
}
Anyway I hope it's useful.
And I can guarantee that magically as soon as I've posted this somebody will reply and say "that's simple! You actually only need to x, y, z"
Such is the way of bloody java programming.
I'm on a horse.