Reputation: 189444
I recently followed Googles Advice on Bitmap Caching in Android and added my own LruCache from the support library. The LruCache works best if the size of the images in bytes is known to the cache.
The problem ist the getByteCount for bitmaps is only available since Android API Level 11.
How would you guess the size of an bitmap in memory?
Upvotes: 0
Views: 1154
Reputation: 15913
From the android.graphics.Bitmap source code:
public final int getByteCount() {
// int result permits bitmaps up to 46,340 x 46,340
return getRowBytes() * getHeight();
}
Both getRowBytes()
and getHeight()
are since API Level 1, so you can implement your own own getByteCount()
for all versions of Android. At a glance, it appears that getByteCount()
was only added for convenience.
Upvotes: 5
Reputation: 17077
Depends on the Bitmap.Config you are using, doesn't it. ARGB_8888 - that should end up somewhere around width * height * 4 bytes unpacked.
Upvotes: 2