adsion
adsion

Reputation: 187

Some confusedness of BitmapFactory.Options.inBitmap

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:

  1. how it works

  2. if I reuse an using bitmap,what will the reused bitmap happen

  3. If this situation will happen:Two images simultaneously on the screen,one reuse another one,then two bitmap the images used will repeat。
  4. how to use inBitmap Correctly

Upvotes: 0

Views: 358

Answers (1)

Cristian Neagu
Cristian Neagu

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 Bitmapor when the resolution or pixel type doesn't match the new one.

Hope this answers your question.

Upvotes: 1

Related Questions