Vincent Williams
Vincent Williams

Reputation: 3136

How does a bitmap cache work?

Can someone explain the difference between a method like this and a bitmap cache? Don't they both just load it into memory? Which one is more efficient?

public static Bitmap loadBitmap(String filename, boolean transparency) {
    InputStream inputStream = null;
    try {
        inputStream = GameMainActivity.assets.open(filename);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Options options = new Options();
    if (transparency) {
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    } else {
        options.inPreferredConfig = Bitmap.Config.RGB_565;
    }
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null,
            options);
    return bitmap;
}

Upvotes: 1

Views: 111

Answers (1)

greywolf82
greywolf82

Reputation: 22173

A cache (in this case a bitmap cache) is used to avoid to create again again the bitmap, so you can speedup things. It's really needed when you need to create the bitmap on-the-fly for example using the Canvas methods.

Upvotes: 1

Related Questions