图形处理

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:

  1. Using canvas.drawBitmap() and extract the Bitmap from the drawable using getBitmap()

  2. 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值