[android-developers] Reusing bitmaps for BitmapFactory.decodeFile and BitmapFactory.Options.inBitmap
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 and this video and it works perfect forBitmapFactory.decodeResource, but not for BitmapFactory.decodeFile. 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?
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
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 android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home