imageloader把图片加载到sd卡: public class MyApplication extends Application{ @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); //默认的方式 //ImageLoaderConfiguration configuration=ImageLoaderConfiguration.createDefault(this); //sdcard的路径 String sdPath=Environment.getExternalStorageDirectory().getPath(); //自定义的方式 ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(480, 800)//内存缓存文件的最大长宽 .discCacheExtraOptions(480, 800, null)//本地缓存的详细信息 .threadPoolSize(3)//线程池内加载的数量 .threadPriority(Thread.NORM_PRIORITY-2)//设置当前线程的优先级 .tasksProcessingOrder(QueueProcessingType.FIFO)//设置任务的处理顺序 .denyCacheImageMultipleSizesInMemory()//防止内存中图片重复 .memoryCache(new LruMemoryCache(2*1024*1024))//设置自己的内存缓存大小 2M .memoryCacheSize(2*1024*1024) .memoryCacheSizePercentage(13)//内存缓存百分比 .discCache(new UnlimitedDiscCache(new File(sdPath+"/huang/image1")))//设置缓存的图片在sdcard中的位置 .discCacheSize(50*1024*1024)//硬盘缓存大小 50M .discCacheFileCount(100)//硬盘缓存文件个数 .discCacheFileNameGenerator(new Md5FileNameGenerator())//md5加密的方式,或new HashCodeFileNameGenerator() .imageDownloader(new BaseImageDownloader(this)) .imageDecoder(new BaseImageDecoder(true))//图片解码 .defaultDisplayImageOptions(getOption())//是否使用默认的图片加载配置,null表示不使用 .writeDebugLogs() .build(); //初始化 ImageLoader.getInstance().init(configuration); }/*
* 设置option
*/
public static DisplayImageOptions getOption(){ DisplayImageOptions option=new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_launcher)//设置图片下载期间显示的图片 .showImageForEmptyUri(R.drawable.emptyurl)//设置图片uri为空或是错误的时候显示的图片 .showImageOnFail(R.drawable.emptyurl)//设置图片加载或解码过程中发生错误显示的图片 .resetViewBeforeLoading(false)//设置图片在加载前是否重置、复位 //.delayBeforeLoading(1000)//下载前的延迟时间 .cacheInMemory(true)//设置下载的图片是否缓存在内存中 .cacheOnDisk(true)//设置下载的图片是否缓存在sd卡中 .considerExifParams(false)//思考可交换的参数 .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)//设置图片的显示比例 .bitmapConfig(Config.RGB_565)//设置图片的解码类型 .displayer(new RoundedBitmapDisplayer(40))//设置图片的圆角半径 .displayer(new FadeInBitmapDisplayer(3000))//设置图片显示的透明度过程的时间 .build(); return option; } }
imageloader加载到sd卡
最新推荐文章于 2021-07-06 15:10:20 发布