
We had faced many issue in handling images for android apps. Since android supports many low end devices we need to concentrate on memory management to avoid the out of memory exception in the app. When we decompressed the images, it took lot of memory which is allocated for the app. This leads the java garbage collector to run frequently, hence slows the apps performance. The problem is especially bad without improvements to the garbage collector made in Android 5.0.
So we analysed and came back with few solutions and used external library to handle the issue for downloading the images from online and also to make round corner, circle and other shapes.
To download the image we used “Universal Image Loader” which is a smart and powerful library that helps in loading, caching and displaying images in Android. This means, using this library you can download remote images and display on ImageView.
Features of Universal Image Loader:
• Asynchronous and multi-threaded image loading. This allows you to download multiple images Asynchronously.
• Supports various configurations that helps to tune for your requirement. With this you can control memory, cache type, decoder, display image options, etc.
• Possibility of image caching in memory and/or on device’s file system (or SD card)
• Possibility to “listen” loading process. Allows various callback methods using which you will get to know the progress/state of your download request.
It’s Free and Open Source
Reference Link: for different image loaders
Be lazy productive android
Image loader useful links:
Android Universal Image Loader – wiki – Useful – Info
Shaping the Images in Android
To reshape the images we use following external jar files to handle in android apps.
RoundedImageView:
It supports rounded corners and ovals/circles. It is a full superset of CircleImageView (which is actually just a subset based on this lib) with many more advanced features like support for ovals, rounded rectangles, ScaleTypes and TileModes. A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the original example from Romain Guy.
Ref Link:RoundedImageView
Advantage:
There are many ways to create rounded corners in android, but this is the fastest and best one because it:
2. Does not use a clipPath which is not hardware accelerated and not anti-aliased.
3. Does not use setXfermode to clip the bitmap and draw twice to the canvas.
4. It has proper support for:
b. Ovals and Circles
c. All ScaleTypes
d. Borders are drawn at view edge, not bitmap edge
e. Except on edges where the bitmap is smaller than the view
f. Borders are not scaled up/down with the image (correct width and radius are maintained)
g. Anti-aliasing
h. Transparent backgrounds
i. Hardware acceleration
j. Support for LayerDrawables (including TransitionDrawables)
k. TileModes for repeating drawables
Dependencies which has to be added in grade file in Android Studio:
dependencies {
compile ‘com.makeramen:roundedimageview:2.2.1’
}
Even we have many other support jar files like “siyamed/android-shape-imageview”, “MostafaGazar/CustomShapeImageView” and “pungrue26/SelectableRoundedImageView” to handle the images in android app. I referred to the RoundedImageView, developed by Vince, in developing this new one, and I really appreciate him.
This also helps you to solve your out of memory issue. Until next time…..