简体   繁体   English

Android:Universal Image Loader-将新图像添加到缓存

[英]Android: Universal Image Loader - Add new image to cache

I am successfully integrate Universal Imageloader in my Gallery App to show the images from the phone storage 我已成功将Universal Imageloader集成到我的Gallery App中,以显示手机存储中的图像

But new images (captured from the camera /processed images) stored in the app's specified folder doesn't appear in the gallery. 但是存储在应用程序指定文件夹中的新图像(从相机/处理过的图像捕获)不会出现在图库中。 even the application restarted. 甚至应用程序重新启动。

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.

I think add the details of new image to the cache will resolve the problem. 我认为将新图像的详细信息添加到缓存将解决此问题。 but don't know how . 但是不知道怎么做。 please help 请帮忙

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 有什么方法可以将新的处理过的图像添加到缓存或已经启动的图像加载器

You just have to load the your image with universal image loader it will automatically cache it. 您只需要使用通用图像加载器加载图像,它将自动缓存它。

Loading 载入中

                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
                    }
                });

UNIVERSAL IMAGE LOADER ACCEPTED URI schemes 通用图像加载器接受的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)

仅在Application类的onCreate()中初始化一次UniversalImageLoader实例,而不在每个Activity或其他地方初始化一次。

我发现这可以使用loadImageSync()函数解决问题。

ImageLoader.getInstance().loadImageSync(filepath);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM