3

I don't want to download images if they are already cached. I am using ImageLoader library by NOSTRA. Please tell me if there is any way to do that. Following is the code:-

    DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .showStubImage(R.drawable.ic_stub)
                        .showImageForEmptyUri(R.drawable.ic_sample)
                        .resetViewBeforeLoading()
                        .cacheInMemory()
                        .cacheOnDisc()
                        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        .bitmapConfig(Bitmap.Config.ARGB_8888)
                        .build();
                imageLoader.displayImage(url2.toString()
                                          ,thumbnail,options, new                                 
                    ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted() {

                       // progressBar.setVisibility(grid.VISIBLE);
                        //  grid.notify();
                    }

                    @Override
                    public void onLoadingFailed(FailReason failReason) {

                       //progressBar.setVisibility(grid.GONE);
                        //  grid.notify();

                    }

                    @Override
                    public void onLoadingComplete(Bitmap bitmap) {


                      //  progressBar.setVisibility(grid.GONE);
                        // grid.notify();
                    }

                    @Override
                    public void onLoadingCancelled() {

                       //  progressBar.setVisibility(grid.GONE);
                        //grid.notify();

                    }
                });
4

1 回答 1

6

您尚未在DisplayImageOption.

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
    .threadPoolSize(5)
    .threadPriority(Thread.MIN_PRIORITY + 3)
    .denyCacheImageMultipleSizesInMemory()
    // 1MB=1048576 
    .memoryCacheSize(1048576 * 5)
    .discCache(new UnlimitedDiscCache(cacheDir))
    .build();

在这里,cacheDir可能是一个目录SD card(需要权限“android.permission.WRITE_EXTERNAL_STORAGE”)或application's cache目录。

我已经cacheDirectory在我的申请中提供了。

File cacheDir = new File(this.getCacheDir(), "name of directory");
    if (!cacheDir.exists())
        cacheDir.mkdir();

ImageLoader现在,在下载任何图像之前,通过以下代码提供您的配置,

imageLoader.init(config);
于 2013-01-21T12:44:09.513 回答