Reputation: 187
As everyone knows, If BitmapFactory.Options.inBitmap option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content.My problems are:
how it works
if I reuse an using bitmap,what will the reused bitmap happen
Upvotes: 0
Views: 358
Reputation: 71
First of all, if you supply a Bitmap
object as an inBitmap
you should make sure that you don't use the supplied Bitmap
in any other place anymore, as its content will most likely be replaced with new data (new pixels).
Second, you must make sure the supplied Bitmap
has the same resolution and type of pixels as the result of the desired operation.
So when should you use the inBitmap
parameter? Whenever you can reuse a Bitmap
that is similar to the one you want to create. Why should you use it? Because it is way more efficient than not doing so. If you supply a reusable Bitmap
, the space it occupies in memory will be used for the new one; the system will not have to allocate new space in memory (usually a bitmap requires a lot of memory space) and the Garbage Collector will not have to recycle it.
When you should not use the parameter? When you are still using the old Bitmap
or when the resolution or pixel type doesn't match the new one.
Hope this answers your question.
Upvotes: 1