bitmap - Android: Difference between canvas.drawBitmap and BitmapDrawable.draw? -
bitmap - Android: Difference between canvas.drawBitmap and BitmapDrawable.draw? -
when want draw bitmapdrawable canvas in android, there 2 possibilities same , don't know 1 prefer:
using canvas.drawbitmap() , extract bitmap drawable using getbitmap()
using drawable.draw(canvas), passing canvas argument drawable.
i'm using first alternative now, seems arbitrary can't see difference.
thanks answers
never alternative number 1 way it. instead of creating bitmap out of drawable every time want draw it, create bitmap in first place. is, don't create drawable if going draw bitmap. create bitmap this:
mbitmap = bitmapfactory.decoderesource(mcontext.getresources(), r.drawable.myimage); mbitmap = bitmap.createscaledbitmap(mbitmap, width, height, true);
and once. after that, draw (canvas.drawbitmap()).
as alternative number 2, doing correctly.
now, there differences. alternative 1 faster draw , background images. there important alter fps depending on if draw bitmap or drawable. bitmaps faster.
option 2 way go if need things scaling, moving , other kinds of manipulations of image. not fast there's no other alternative if want of things mentioned.
hope helps!
android bitmap drawable
Comments
Post a Comment