How To Make Application More Responsive Which Uses Several Bitmaps?
Solution 1:
You can try this library which handles bitmap very efficiently. https://github.com/thest1/LazyList Its very easy to use this lazy list library. It does the job of caching bitmap automatically:-
ImageLoader imageLoader=newImageLoader(context);
imageLoader.DisplayImage(url, imageView);
NOTE :
<uses-permissionandroid:name="android.permission.INTERNET"/><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
and also you can look into Nostras ImageLoader, as it efficiently handles loading images into specific sized containers, i.e resizing and compressing them, before you will need to handle them. It also supports content uris which will help you all at once.
Besides this,it’s not worth loading a 1024x768 pixel image into memory if it will eventually be displayed in a 128x96 pixel thumbnail in an ImageView. You should load a scaled down version of image into memory. I am also sharing wonderful utility class for bitmap which helps you to scale down your image according to size:-
BitmapUtil.java
/**
* Provides static functions to decode bitmaps at the optimal size
*/publicclassBitmapUtil {
privateBitmapUtil() {}
/**
* Returns Width or Height of the picture, depending on which size is smaller. Doesn't actually
* decode the picture, so it is pretty efficient to run.
*/publicstaticintgetSmallerExtentFromBytes(byte[] bytes) {
final BitmapFactory.Options options = new BitmapFactory.Options();
// don't actually decode the picture, just return its bounds
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
// test what the best sample size isreturn Math.min(options.outWidth, options.outHeight);
}
/**
* Finds the optimal sampleSize for loading the picture
* @param originalSmallerExtent Width or height of the picture, whichever is smaller
* @param targetExtent Width or height of the target view, whichever is bigger.
*
* If either one of the parameters is 0 or smaller, no sampling is applied
*/publicstaticintfindOptimalSampleSize(int originalSmallerExtent, int targetExtent) {
// If we don't know sizes, we can't do sampling.if (targetExtent < 1) return1;
if (originalSmallerExtent < 1) return1;
// test what the best sample size isint extent = originalSmallerExtent;
int sampleSize = 1;
while ((extent >> 1) >= targetExtent) {
sampleSize <<= 1;
extent >>= 1;
}
return sampleSize;
}
/**
* Decodes the bitmap with the given sample size
*/publicstatic Bitmap decodeBitmapFromBytes(byte[] bytes, int sampleSize) {
final BitmapFactory.Options options;
if (sampleSize <= 1) {
options = null;
} else {
options = new BitmapFactory.Options();
options.inSampleSize = sampleSize;
}
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
}
}
also You can go to this link It will help you to build the app http://developer.android.com/training/displaying-bitmaps/index.html
Solution 2:
Use Lazy loading and Image loader classes in android to set image on imageView so it will look like more responsive Here is some tutorial links for this
Post a Comment for "How To Make Application More Responsive Which Uses Several Bitmaps?"