0

我成功整合通用ImageLoader的在我的相冊應用從手機存儲安卓:通用圖像裝載機 - 添加新的圖像緩存

但新圖像(從攝像機/處理圖像捕捉)顯示圖像存儲在該應用的指定文件夾不會出現在圖庫中。即使應用程序重新啓動。

可能是因爲這個錯誤

W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first. 

我想添加新的圖像緩存的細節將解決此問題。但不知道如何。請幫助

代碼:活動擴展應用

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

加載所有專輯

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

有沒有什麼辦法來新處理的圖像添加到緩存中或已經啓動的圖像加載器

回答

2

你只需要加載你的圖像與通用圖像加載器它會自動緩存它。

加載

   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圖像加載器ACCEPTED 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) 
+0

先生,我需要添加新的處理過的圖像已經啓動的圖像加載器..是否有可能 –

+0

你意味着你從相機得到一張照片,你也希望它緩存在通用圖像加載器的權利? –

+0

是的...我將新圖像保存到應用程序文件夾..需要添加到緩存 –

0

裏面你ApplicationonCreate()初始化您UniversalImageLoader情況只有一次,而不是每個Activity或其他地方內。

+0

謝謝..這只是開始一次..我需要新的加工/保存的圖像添加到已經啓動的ImageLoader的是......可能 –

+0

您通過添加圖像ImageLoader的意思是什麼?如果你這樣配置,庫會自動緩存加載的圖像。 –

0

我發現,這將使用函數loadImageSync()reslove問題;

ImageLoader.getInstance().loadImageSync(filepath);