Android:通用图像加载器 - 将新图像添加到缓存
Android: Universal Image Loader - Add new image to cache
我已成功将 Universal Imageloader 集成到我的图库应用程序中以显示来自 phone 存储的图像
但是存储在应用程序指定文件夹中的新图像(从相机捕获/处理过的图像)不会出现在图库中。甚至应用程序重新启动。
May be due to this error
W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
我认为将新图片的详细信息添加到缓存中可以解决问题。但不知道如何。请帮忙
code : Activity Extends Application
DisplayImageOptions defaultDisplayImageOptions = new DisplayImageOptions.Builder() //
.considerExifParams(true)
.resetViewBeforeLoading(true)
.showImageOnLoading(R.drawable.nophotos)
.showImageOnFail(R.drawable.nophotos)
.delayBeforeLoading(0)
.build(); //
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultDisplayImageOptions)
.memoryCacheExtraOptions(480, 800).threadPoolSize(5)
.build();
ImageLoader.getInstance().init(config);
load all album
PhoneMediaControl mediaControl = new PhoneMediaControl();
mediaControl.setLoadalbumphoto(new loadAlbumPhoto() {
@Override
public void loadPhoto(ArrayList<AlbumEntry> albumsSorted_) {
albumsSorted = new ArrayList<PhoneMediaControl.AlbumEntry>(albumsSorted_);
if (mView != null && mView.getEmptyView() == null) {
mView.setEmptyView(null);
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
});
mediaControl.loadGalleryPhotosAlbums(mContext, 0);
is there any way to add new processed image to the cache or already initiated imageloader
仅在 Application
class 的 onCreate()
内初始化您的 UniversalImageLoader
实例一次,而不是在每个 Activity
或其他地方。
您只需使用通用图片加载器加载您的图片,它会自动缓存它。
加载中
ImageLoader imageLoader = ImageLoader.getInstance();
Uri uri = Uri.fromFile(new File("/DCIM/Camera/1470634175974.jpg"));
imageLoader.loadImage(uri.toString(), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});
通用图像加载器接受的 URI 方案
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)
我发现这将使用函数 load Image aSync();
解决问题
ImageLoader.getInstance().loadImageSync(filepath);
我已成功将 Universal Imageloader 集成到我的图库应用程序中以显示来自 phone 存储的图像
但是存储在应用程序指定文件夹中的新图像(从相机捕获/处理过的图像)不会出现在图库中。甚至应用程序重新启动。
May be due to this error
W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
我认为将新图片的详细信息添加到缓存中可以解决问题。但不知道如何。请帮忙
code : Activity Extends Application
DisplayImageOptions defaultDisplayImageOptions = new DisplayImageOptions.Builder() //
.considerExifParams(true)
.resetViewBeforeLoading(true)
.showImageOnLoading(R.drawable.nophotos)
.showImageOnFail(R.drawable.nophotos)
.delayBeforeLoading(0)
.build(); //
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultDisplayImageOptions)
.memoryCacheExtraOptions(480, 800).threadPoolSize(5)
.build();
ImageLoader.getInstance().init(config);
load all album
PhoneMediaControl mediaControl = new PhoneMediaControl();
mediaControl.setLoadalbumphoto(new loadAlbumPhoto() {
@Override
public void loadPhoto(ArrayList<AlbumEntry> albumsSorted_) {
albumsSorted = new ArrayList<PhoneMediaControl.AlbumEntry>(albumsSorted_);
if (mView != null && mView.getEmptyView() == null) {
mView.setEmptyView(null);
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
});
mediaControl.loadGalleryPhotosAlbums(mContext, 0);
is there any way to add new processed image to the cache or already initiated imageloader
仅在 Application
class 的 onCreate()
内初始化您的 UniversalImageLoader
实例一次,而不是在每个 Activity
或其他地方。
您只需使用通用图片加载器加载您的图片,它会自动缓存它。
加载中
ImageLoader imageLoader = ImageLoader.getInstance();
Uri uri = Uri.fromFile(new File("/DCIM/Camera/1470634175974.jpg"));
imageLoader.loadImage(uri.toString(), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});
通用图像加载器接受的 URI 方案
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)
我发现这将使用函数 load Image aSync();
解决问题ImageLoader.getInstance().loadImageSync(filepath);