http://stackoverflow.com/questions/6681108/android-difference-between-canvas-drawbitmap-and-bitmapdrawable-draw
------------------------------------------------------------------------------------------------------------------------------------------------
When I want to draw a BitmapDrawable to a Canvas in Android, there are two possibilities that do the same and I don't know which one to prefer:
-
Using canvas.drawBitmap() and extract the Bitmap from the drawable using getBitmap()
-
Using drawable.draw(canvas), passing the canvas as an argument to the drawable.
I'm using the first option now, but it seems completely arbitrary as I can't see any difference.
Thanks for your answers
------------------------------------------------------------------------------------------------------------------------------------------------
Never do option number 1 the way you do it. Instead of creating a bitmap out of a drawable every time you want to draw it, create a bitmap in the first place. That is, don't create a Drawable if you are going to draw a bitmap. Create a bitmap like this:mBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.myImage);
mBitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true);
And this is something you do just once. After that, just draw like you do (canvas.drawbitmap()).
As for option number 2, you are doing it correctly.
Now, there are some differences. Option 1 is faster to draw and usually good for background images. There is a significant change to FPS depending on if you draw a bitmap or drawable. Bitmaps are faster.
Option 2 is the way to go if you need to things like scaling, moving and other kinds of manipulations of the image. Not as fast but there's no other option if you want to do any of those things just mentioned.
Hope this helps!
------------------------------------------------------------------------------------------------------------------------------------------------
硬件加速
http://developer.android.com/guide/topics/graphics/hardware-accel.html