I have a ListView that I need to populate with PNGs from Assets.  My
problem is that I want to reuse Bitmaps as the ListView scrolls.

I am running Honeycomb and I see that BitmapFactory.Options has the
field inBitmap, which I am setting. Unfortunately, I keep getting a
stack trace when I call "BitmapFactory.decodeStream (InputStream is,
Rect outPadding, BitmapFactory.Options opts)":

D/skia    ( 2310): --- decoder->decode returned false
D/App: Exception :java.lang.IllegalArgumentException: Problem decoding
into existing bitmap and Message:Problem decoding into existing bitmap
W/System.err( 2310): java.lang.IllegalArgumentException: Problem
decoding into existing bitmap
W/System.err( 2310):    at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:496)


My code looks like the following, and fails in the getLogo() method.

public class SomeClass {
  private static BitmapFactory.Options sBitmapOptions;

  public static Bitmap getLogo() {

    if (sBitmapOptions == null) {
      initOptions();
    }

    Bitmap bitmap = getBitMap();
    Rect rect = new Rect();
    sBitmapOptions.inBitmap = bitmap;

    //
    // exception thrown here.
    //
    Bitmap decodedBitmap = BitmapFactory
      .decodeStream(assetManager.open("somefile.png"),
                    rect,
                    sBitmapOptions);

    return decodedBitmap;
  }

  private static void initOptions() {
    sBitmapOptions = new BitmapFactory.Options();
    sBitmapOptions.inDither = false;
    sBitmapOptions.inScaled = true;
    sBitmapOptions.inSampleSize = 1;
    sBitmapOptions.inPurgeable = false;
  }

  private static Bitmap getBitMap() {
    // has logic to return new or recycled bitmap...
  }

}

Any ideas/suggestions or sample code of reusing Bitmaps?

Thanks-
Elliot

-- 
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

Reply via email to