0

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.

AbiAndroid
  • 89
  • 2
  • 4
  • 14

1 Answers1

1

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.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Thank you ..but based on my requirement I don't want to scale down image.I am doing a image stegnography application. I am getting image from galley and hide text in it.While fetching image dimension of '3215*1525' memory issue is there...so in my case I want to hide large dimension image from gallery which is taken from my application. – AbiAndroid Mar 28 '13 at 06:50
  • Are you displaying large number of images. In that case use UIL. I am looking forward to an alternate solution if others can suggest. To understand better you should look at the link mentioned. – Raghunandan Mar 28 '13 at 06:52
  • http://stackoverflow.com/questions/3331527/android-resize-a-large-bitmap-file-to-scaled-output-file. I am very curious to look at an alternative solution – Raghunandan Mar 28 '13 at 06:57
  • I just want to fetch single image from gallery inside my application.Any suggestion.... – AbiAndroid Mar 28 '13 at 06:58
  • I do not know an alternatvie other than scaling down. Go through the first link suggested above. – Raghunandan Mar 28 '13 at 06:58
  • Ok thank you ... I will check dimension of image programatically and scale down image, if image is too large – AbiAndroid Mar 28 '13 at 07:26