Displaying simple bitmap on Android
beginner in graphics here! I'm trying to display a simple image on my
device, but nothing appears, and the log doesn't show any bug. The program
runs but nothing happens.
Here is my code
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.droid_1),
10, 10, null);
}
and the cal of this method
public void run() {
Canvas canvas;
long tickCount = 0;
Log.d(TAG, "starting game loop");
while (running) {
canvas = null;
//try locking the canvas for exclusive pixel editing on the
surface
try
{
canvas = this.surfaceHolder.lockCanvas();
synchronized (surfaceHolder)
{
//update the game state
//draws the canvas on the panel
this.gamePanel.draw(canvas);
}
}
finally
{
//in case of an exception the surface is not left in
//an inconsistent state
if (canvas != null)
{
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
The picture does exist in the /res/drawablemdpi directory.
Thanks for your help!
No comments:
Post a Comment