I am able to open an image / picture in the Gallery from inside my application. But I am getting memory issue while fetching a large image.
Is there is any way to show images from galley based on image dimension?
Please help me to fix this issue.
I am able to open an image / picture in the Gallery from inside my application. But I am getting memory issue while fetching a large image.
Is there is any way to show images from galley based on image dimension?
Please help me to fix this issue.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
The link guides you on how to load bitmaps efficiently especialcy the topic under Load a Scaled Down Version into Memory
You should recycle bitmaps when not in use.
bitmaps.recycle();
Bitmaps are also stored on heap starting from honeycomb.So recycle bitmaps when not in use.
http://www.youtube.com/watch?v=_CruQY55HOk. If you run into memory leaks use a MAT Analyzer to find and fix it. The video has a talk on the topic. It also explains how to manage memory.
If you want to display large number of bitmaps use a Universal Image Loader. Use a listview or grdiview to display images.
https://github.com/nostra13/Android-Universal-Image-Loader.
It is based on Lazy List(works on same principle). But it has lot of other configurations. I would prefer to use Universal Image Loader coz it gives you more configuration options. You can display a error image if downlaod failed. Can display images with rounded corners. Can cache on disc or memory. Can compress image.
In your custom adapter constructor
File cacheDir = StorageUtils.getOwnCacheDirectory(a, "your folder");
// Get singletone instance of ImageLoader
imageLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//display stub image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
In your getView()
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options.
You can configure with other options to suit your needs.
Along with lazy loading/Universal Image Loader you can view holder for smooth scrolling and performance. http://developer.android.com/training/improving-layouts/smooth-scrolling.html.