Better frame rate drawing bitmaps in a Canvas (Part 2)?
Here's what I'm trying to do: I'm trying to load a sequence of bitmaps to display an animation. That means that I need to have a descent fps (24 fps). I need to load no more than 10 seconds of animations or about 300 bitmaps. And since it's a live wallpaper I'm limited to manually drawing each frame.
Here's what I tried so far:
- The obvious strategy: load each bitmap each frame and draw it. This is slow.
- Use caching. I put the bitmap loading in a seperate thread. A cache of about 20 bitmaps continously load in the background. However, I still get poor performance (about 10 fps). The culprit is slow bitmap loading.
- I was going to try using OpenGL but then I realized that even with OpenGL, the slow bitmap loading will still be a problem. Right? (Or am I wrong?)
So what other strategies can I use?
Here's what I had in mind: if I use openGL, I can use smaller bitmaps (because it gives better scaling). Perhaps then I can have a bigger cache - say perhaps 3 seconds. With a larger cache, the slow bitmap loading will not be a problem, right?
Any other strategies?
Oh and this is my current bitmap loading function:
void loadNthBitmap(int i, int n) {
try {
buf = new
BufferedInputStream(assets.
open(folder+"/"
+imageList[n])
);
tmpBitmap = BitmapFactory.
decodeStream(buf);
rbitmap[i] = Bitmap.createBitmap
(tmpBitmap,
0,0,imageWidth,imageHeight,
transMatrix,false);
}
catch(IOException e) {}
}
开发者_StackOverflow中文版where imageList
is pre-defined list of assets and transMatrix
is a rotation and scaling matrix.
What you're trying to do (i.e. full-frame animation) is not easy. Almost all Android animation (from the Lunar Lander example in the SDK to Angry Birds) consists of moving small sprites on a relatively static background.
The "obvious" solution to your problem would be to turn your animation into an mpeg and then decode it as a video live wallpaper, replicating the approach that this guy took here: http://forum.xda-developers.com/showthread.php?t=804720 (alternative link http://android.ccpcreations.com/vlw/)
精彩评论