问题
Using Universal Image Loader, is it possible to directly save images to disk and reuse those images between different runs of the application?
I know imageLoader.displayImage(imageURI, itemHolder.image, options);
gets images from the cache the second time, but if you exit the app the cache is removed.
I want the display image method to save the image to a permanent location and use that location every time the app calls that method.
Is this possible using Universal Image Loader or do I need to find another way?
回答1:
Try to use
.discCache(new FileCountLimitedDiscCache(cacheDir, new Md5FileNameGenerator(), 1000))
option in ImageLoaderConfiguration
It work for me.
回答2:
you can save the image to a hidden folder then re-use it any time.
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/.saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
and this in your manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
note the .
I inserted before the folder name, which will make the folder hidden.
来源:https://stackoverflow.com/questions/18812411/universal-image-loader-reuse-images