如何使用通用的图像加载器脱机缓存? [英] How To Use universal image loader offline caching?

查看:176
本文介绍了如何使用通用的图像加载器脱机缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用通用的图像加载器捕捉下线? 如果可能的话,如何使用它? 使用的configs? 如何手动设置下载目录?

Is it possible to catch offline using universal image loader? If possible, how to use it? Using configs? How To Set Download Directory manually?

出现内存不足的erroron负载巨大的图片:

out of memory erroron load huge images :

我的codeS:

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .cacheOnDisc(true).cacheInMemory(true)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .displayer(new FadeInBitmapDisplayer(300)).build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(G.appConfigs.context)
            .defaultDisplayImageOptions(defaultOptions)
            .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
            .diskCacheExtraOptions(480, 800, null)
            .memoryCache(new WeakMemoryCache())
            .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
            .memoryCacheSize(2 * 1024 * 1024)
            .discCacheSize(300 * 1024 * 1024)
            .build();
    ImageLoader.getInstance().init(config);
    // END - UNIVERSAL IMAGE LOADER SETUP

    ImageLoader imageLoader = ImageLoader.getInstance();

        DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
            .cacheOnDisc(true).resetViewBeforeLoading(true)
            .showImageForEmptyUri(R.drawable.no_pic)
            .showImageOnFail(R.drawable.load_failed)
            .showImageOnLoading(R.drawable.img_thumb).build();

    //download and display image from url
    imageLoader.displayImage(imgURL, img, options);

如何解决呢?

how to resolve it ?

推荐答案

您可以使用<一个href="https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java"><$c$c>ImageLoaderConfiguration.Builder一流的定制磁盘缓存。这包括方法:

You can use the ImageLoaderConfiguration.Builder class to customize disk caching. This includes the methods:

  • diskCacheExtraOptions()
  • diskCacheSize()(以字节为单位)。
  • diskCacheFileCount()
  • diskCacheFileNameGenerator()
  • 和其他一些人。
  • diskCacheExtraOptions()
  • diskCacheSize() (in bytes).
  • diskCacheFileCount()
  • diskCacheFileNameGenerator()
  • and some others.

或者你也可以使用 diskCache(DiskCache)来实现脱机缓存提供了一个自定义类。

Or you can just use diskCache(DiskCache) to provide a custom class for implementing offline caching.

从维基的配置部分的示例:

From the example in the Configuration section of the wiki:

File cacheDir = StorageUtils.getCacheDirectory(context);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
        .diskCacheExtraOptions(480, 800, null)
        .taskExecutor(...)
        .taskExecutorForCachedImages(...)
        .threadPoolSize(3) // default
        .threadPriority(Thread.NORM_PRIORITY - 1) // default
        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
        .denyCacheImageMultipleSizesInMemory()
        .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
        .memoryCacheSize(2 * 1024 * 1024)
        .memoryCacheSizePercentage(13) // default
        .diskCache(new UnlimitedDiscCache(cacheDir)) // default
        .diskCacheSize(50 * 1024 * 1024)
        .diskCacheFileCount(100)
        .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
        .imageDownloader(new BaseImageDownloader(context)) // default
        .imageDecoder(new BaseImageDecoder()) // default
        .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
        .writeDebugLogs()
        .build();

这篇关于如何使用通用的图像加载器脱机缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆