Reputation: 3136
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
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