My app decodes a lot of bitmaps from sd card, so I want to reuse existing
bitmaps to decrease GC work. I see examples from Android
Training<http://developer.android.com/training/displaying-bitmaps/manage-memory.html#inBitmap>and
this
video <http://www.youtube.com/watch?v=rsQet4nBVi8>
<http://savefrom.net/?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrsQet4nBVi8&utm_source=chromelite&utm_medium=extensions&utm_campaign=link_modifier>and
it works perfect for
BitmapFactory.decodeResource<http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeResource%28android.content.res.Resources,%20int,%20android.graphics.BitmapFactory.Options%29>,
but not for
BitmapFactory.decodeFile<http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeFile%28java.lang.String,%20android.graphics.BitmapFactory.Options%29>.
I use next code:
private void testBitmapReusing() {
BitmapFactory.Options options = newOptions();
Bitmap bitmap = decode(options);
options.inBitmap = bitmap;
bitmap = decode(options);
}
private BitmapFactory.Options newOptions() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inMutable = true;
return options;
}
private Bitmap decode(BitmapFactory.Options options) {
return BitmapFactory.decodeFile("/mnt/sdcard/sun.jpg", options);
// return BitmapFactory.decodeResource(getResources(), R.drawable.sun,
options);
}
Commented code (BitmapFactory.decodeResource) works as expected, it decodes
new bitmap using existing bitmap. But uncommented code
(BitmapFactory.decodeFile) doesn't decode new bitmap. It just writes to log
message "E/BitmapFactory: Unable to decode stream:
java.lang.IllegalArgumentException: Problem decoding into existing bitmap"
So where is my mistake?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.