首页 > 其他 > 详细

图片加载

时间:2015-10-22 18:48:14      阅读:174      评论:0      收藏:0      [点我收藏+]

package com.bdkj.gmys.utils;

import java.io.File;

import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration.Builder;

/**
 * 该类与universal-image-loader-1.9.2.jar异步图片加载库一起用
 */
public class ImageUtils {
    /**
     *
     * 获取ImageLoader配置信息
     *
     * @param context
     *            上下文对象
     * @param file
     *            图片缓存路径
     * @return
     */
    public static ImageLoaderConfiguration getImageLoaderConfig(
            Context context, File file) {
        Builder builder = new ImageLoaderConfiguration.Builder(context).threadPoolSize(3).memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSizePercentage(13).writeDebugLogs();
        if (file != null) {
            if (!file.exists()) {
                file.mkdirs();
            }
            builder.diskCache(new LruDiscCache(file, new HashCodeFileNameGenerator(), 30 * 1024 * 1024)).diskCacheFileCount(100);
        }
        ImageLoaderConfiguration config2 = builder.build();
        return config2;
    }

    /**
     * 获取默认的ImageLoader图片加载方式
     *
     * @return
     */
    public static DisplayImageOptions getOptions() {
        return new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).build();
    }

    /**
     * 获取指定默认图的ImageLoader图片加载方式
     *
     * @param defaultImage
     *            默认图,如R.drawable.ic_launcher
     * @return
     */
    public static DisplayImageOptions getOptions(int defaultImage) {
        return new DisplayImageOptions.Builder().cacheInMemory(true).showImageForEmptyUri(defaultImage).showImageOnFail(defaultImage).showImageOnLoading(defaultImage).cacheOnDisk(true).build();
    }
}

图片加载

原文:http://www.cnblogs.com/qwer520/p/4901576.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!