In order to support different size of screen resolutions, I programmatically scale the bitmaps in my android game application using SurfaceView. I performed it by using drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
method. I saw a Bitmap
method named as createScaledBitmap that can create a new bitmap scaled from an existing bitmap. Is there a performance difference between them?
Yes, there is. They do different things. createScaledBitmap takes a bitmap and creates a new scaled copy in memory. It does not place it on a canvas, this is a new bitmap object that can later be drawn to a canvas. drawBitmap draws the bitmap to the canvas (which may be backed by a bitmap, surface, or the screen), scales it, applies effects from the paint object, respects clipping regions, etc.
You should not use drawBitmap unless you actually want to draw it to a canvas- using it just to scale is inefficient. If you need to draw it and scale it- if you'll need to scale it repeatedly and memory isn't an issue, use createScaledBitmap first and then draw that scaled bitmap. If you don't need to draw it again or memory is an issue, use drawBitmap to scale it as you draw it.