I just started writing a live wallpaper.
What I would like to do is to set the background to a bitmap from my resources. And I will draw my animations on top of this.
What is the most efficient way to do this? Is there a way to set the background to a bitmap in a live wallpaper? Do I just need to draw the bitmap into the canvas each time before I draw my animations (which seems like it might be hideously inefficient)?
thanks,
Jay
This is what I found.
From the eclipse graphic documentation:
Note: On each pass you retrieve the Canvas from the SurfaceHolder, the previous state of the Canvas will be retained. In order to properly animate your graphics, you must re-paint the entire surface. For example, you can clear the previous state of the Canvas by filling in a color with drawColor() or setting a background image with drawBitmap(). Otherwise, you will see traces of the drawings you previously performed
So the code I used is as follows:
in onCreate() mBitmapBase = BitmapFactory.decodeResource(getResources(), R.drawable.bidBackground);
in onSurfaceChanged() // size the background bitmap so it draws efficiently mBitmapBackground = Bitmap.createScaledBitmap(mBitmapBackground, xMax, yMax, true);
and in Run() try { canvas = sHolder.lockCanvas(); if (canvas != null) canvas.drawBitmap(mBitmapBackground, 0, 0, null);
As far as I can tell this is as efficient as it can get. Although if anybody can correct me on this I would love to hear it.