Share

engineering

1min read

Android ImageCache and WebImageView

Android ImageCache and WebImageView

We’ve released another Open Source Project android-image-cache. Our latest library helps out with memory issues with Bitmaps on Android. It takes advantage of both Level 1 and Level 2 LruCache’s. Level 1 Cache provides in-memory access to recently used Bitmap Objects. Level 2 uses the file system to provide access for older compressed bitmaps. Combining both Levels gives us on one side fast access to bitmaps and on the other side the chance to extend a device’s operational memory.

The Cache is shipped as a jar library and can be used for pretty much any image serving app. We have also prepared a WebImageView which extends Android’s ImageView by adding the method setImageURL allowing developers to easily load an image from a web resource!

public void setImageURL(final String path) {
  imageCache.get(path, new OnCacheResultListener() {
    public void onCacheMiss(final String key) {

      webClient.requestForImage(path, new WebCallback() {		      
	public void onWebHit(final String path, final Bitmap bitmap) {
	  imageCache.put(path, bmp);
	  setBitmap(path, bmp);
	}
      });
    }

    public void onCacheHit(final String key, final Bitmap bitmap) {
      setBitmap(key, bitmap);
    }
  }
}

Bon Appetite!

Share

Przemysław

Software Engineer

Did you enjoy the read?

If you have any questions, don’t hesitate to ask!

Did you enjoy the read?

If you have any questions, don’t hesitate to ask!