/** * 初始化图片载入框架 */ private void initImageLoader() { File cacheDir = StorageUtils.getCacheDirectory(this); int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory()); // System.out.println("dsa-->"+MAXMEMONRY+" "+(MAXMEMONRY/5));//.memoryCache(new // LruMemoryCache(50 * 1024 * 1024)) DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( this).memoryCacheExtraOptions(480, 800).defaultDisplayImageOptions(defaultOptions) .diskCacheExtraOptions(480, 800, null).threadPoolSize(3) .threadPriority(Thread.NORM_PRIORITY - 2) .tasksProcessingOrder(QueueProcessingType.FIFO) .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(MAXMEMONRY / 5)) .diskCache(new UnlimitedDiskCache(cacheDir)) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(this)) // default .imageDecoder(new BaseImageDecoder(false)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()).build(); ImageLoader.getInstance().init(config); }
private void initImageLoader(){ Context context = getApplicationContext(); File cacheDir = StorageUtils.getCacheDirectory(context); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) .threadPriority(Thread.NORM_PRIORITY - 2) // 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(false)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default // .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); }
public static ImageLoaderConfiguration.Builder getDefaultImageLoaderConfigurationBuilder(Context context) { File cacheDir = StorageUtils.getCacheDirectory(context); ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context) // .memoryCacheExtraOptions(480, 800) // default = device screen dimensions // .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null) .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 .discCache(new UnlimitedDiscCache(cacheDir)) // default // .discCacheSize(50 * 1024 * 1024) .discCacheFileCount(1000) .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default .imageDecoder(new BaseImageDecoder(false)) // default // .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .defaultDisplayImageOptions(getDefaultImageOptions()); return builder; }
/** * Get default ImageLoaderConfiguration.Builder,and you can easily change the builder. * @param context * @return */ public static ImageLoaderConfiguration.Builder getDefaultImageLoaderConfigurationBuilder(Context context) { File cacheDir = StorageUtils.getCacheDirectory(context); ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context) // .memoryCacheExtraOptions(480, 800) // default = device screen dimensions // .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null) .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 UnlimitedDiskCache(cacheDir)) // default // .discCacheSize(50 * 1024 * 1024) .diskCacheFileCount(1000) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default .imageDecoder(new BaseImageDecoder(false)) // default // .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .defaultDisplayImageOptions(getDefaultImageOptions()); return builder; }
public static void initImageLoader(Context context) { File cacheDir = StorageUtils.getCacheDirectory(context); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .denyCacheImageMultipleSizesInMemory() .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null) .threadPriority(Thread.NORM_PRIORITY - 2) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .discCache(new UnlimitedDiscCache(cacheDir)) // default .discCacheSize(50 * 1024 * 1024) .discCacheFileCount(100) .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default .imageDecoder(new BaseImageDecoder(true)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); }
/** * @return void * @Title: initImageLoader * @Description: TODO */ private void initImageLoader() { DisplayImageOptions imageOptions = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.default_background) .showImageOnFail(R.drawable.default_background) .cacheInMemory(true).cacheOnDisk(true) .resetViewBeforeLoading(true).considerExifParams(false) .bitmapConfig(Bitmap.Config.RGB_565).build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(480, 800) .diskCacheExtraOptions(480, 800, null) .threadPoolSize(5) .threadPriority(Thread.NORM_PRIORITY) .tasksProcessingOrder(QueueProcessingType.LIFO) .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(10) // .diskCache( // new UnlimitedDiscCache(StorageUtils.getCacheDirectory( // this, true))) .diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) .imageDownloader(new BaseImageDownloader(this)) .imageDecoder(new BaseImageDecoder(false)) .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .defaultDisplayImageOptions(imageOptions).build(); ImageLoader.getInstance().init(config); }
private void initImageLoader() { File cacheDir = FileUtil.getCacheDirectory(this, FilePathConfig.PATH_IMAGEDOWNLOADER); DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.default_imageview_background) // resource or drawable .showImageForEmptyUri(R.drawable.default_imageview_background) // resource or drawable .showImageOnFail(R.drawable.default_imageview_background) // resource or drawable .resetViewBeforeLoading(false) // default .delayBeforeLoading(200) .cacheInMemory(true) .cacheOnDisk(true) .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default .bitmapConfig(Bitmap.Config.ARGB_8888) // default .displayer(new SimpleBitmapDisplayer()) // default .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 2) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(20 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .diskCache(new UnlimitedDiskCache(cacheDir)) // default .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(getApplicationContext())) // default .imageDecoder(new BaseImageDecoder(false)) // default .defaultDisplayImageOptions(options) .build(); ImageLoader.getInstance().init(config); }
private ImageLoaderConfiguration getLoaderConfig() { return new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(320, 600) .threadPoolSize(4) .threadPriority(Thread.NORM_PRIORITY - 1) .tasksProcessingOrder(QueueProcessingType.FIFO) .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(20 * 1024 * 1024)) .diskCacheSize(20 * 1024 * 1024) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .imageDownloader(new BaseImageDownloader(this)) .imageDecoder(new BaseImageDecoder(true)) .defaultDisplayImageOptions(getOptions()) .build(); }
/** * 初始化ImageLoader * * @param context */ private static void initImageLoader(Context context) { if (sConfig != null) { return; } File cacheDir = StorageUtils.getCacheDirectory(context); sConfig = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .denyCacheImageMultipleSizesInMemory() .threadPriority(Thread.NORM_PRIORITY - 2) // default .tasksProcessingOrder(QueueProcessingType.LIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(10 * 1024 * 1024)) .memoryCacheSize(10 * 1024 * 1024) .memoryCacheSizePercentage(13) .diskCache(new UnlimitedDiskCache(cacheDir)) // default .diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default .imageDecoder(new BaseImageDecoder(true)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs().build(); ImageLoader.getInstance().init(sConfig); }
/** * initial Universal ImageLoader * * @param applicationContext */ public static void initImageLoader(Context applicationContext) { File cacheDir = null; if (FileSystem.available()) cacheDir = StorageUtils.getOwnCacheDirectory(applicationContext, FileSystem.getDirectoryPath(DefaultFileDirectoryContext.FILE_DIRECTORY_TYPE_PICTURE)); else cacheDir = StorageUtils.getCacheDirectory(applicationContext); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(applicationContext) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 2) // 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(applicationContext)) // default .imageDecoder(new BaseImageDecoder(true)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); }
public static ImageLoaderConfiguration getImageLoaderConfiguration(Context context) { final int MEMORY_CACHE_LIMIT = 2 * 1024 * 1024; final int THREAD_POOL_SIZE = 3; ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(context) .threadPoolSize(THREAD_POOL_SIZE).threadPriority(Thread.NORM_PRIORITY) .denyCacheImageMultipleSizesInMemory() .memoryCache(new UsingFreqLimitedMemoryCache(MEMORY_CACHE_LIMIT)) .defaultDisplayImageOptions(ImageLoaderUtils.UIL_DEFAULT_DISPLAY_OPTIONS) .imageDecoder(new SmartUriDecoder(context, new BaseImageDecoder(false))) .denyCacheImageMultipleSizesInMemory() .discCacheFileNameGenerator(new HashCodeFileNameGeneratorWithoutToken()).build(); return imageLoaderConfiguration; }
public SmartUriDecoder(Context context, BaseImageDecoder imageUriDecoder) { if (imageUriDecoder == null) { throw new NullPointerException("Image decoder can't be null"); } this.context = new WeakReference(context); this.imageUriDecoder = imageUriDecoder; }
/** Creates default implementation of {@link ImageDecoder} - {@link BaseImageDecoder} */ public static ImageDecoder createImageDecoder(boolean loggingEnabled) { return new BaseImageDecoder(loggingEnabled); }
public static ImageDecoder createImageDecoder(boolean loggingEnabled) { return new BaseImageDecoder(loggingEnabled); }
public ThumbnailDecoder(ContentResolver cr, BaseImageDecoder baseDecoder) { contentResolver = cr; baseImageDecoder = baseDecoder; }
/** Creates default implementation of {@link com.nostra13.universalimageloader.core.decode.ImageDecoder} - {@link com.nostra13.universalimageloader.core.decode.BaseImageDecoder} */ public static ImageDecoder createImageDecoder(boolean loggingEnabled) { return new BaseImageDecoder(loggingEnabled); }
private void uploadImg() { if (mDialogSearching == null) { mDialogSearching = new DialogSearching(getActivity()); } mDialogSearching.setContent(R.string.z_toast_modifying); mDialogSearching.show(); new Handler().post(new Runnable() { @Override public void run() { new Thread() { @Override public void run() { Message msg = new Message(); msg.what = 1; msg.obj = null; try { ImageSize imageSize = BaseImageDecoder.getImageSize(mImagePath); BaseResponse<String> base = new Gson().fromJson((String) FormFile.postDatas(CommonUtils.getImageByteByPath(mImagePath, imageSize), imageSize == null ? null : imageSize.getMimeType()), new TypeToken<BaseResponse<String>>() { }.getType()); msg.obj = base; if (base.error_code == 0) { String fileName = new HashCodeFileNameGenerator().generate(base.data); MediaStoreUtils.copyFile(mImagePath, SdCacheTools.getOwnImageCacheDir(mContext) + "/" + fileName); File file = new File(mImagePath); if (!file.exists()) { file.delete(); } } } catch (Throwable e) { e.printStackTrace(); msg.obj = null; } mHanlder.sendMessage(msg); } }.start(); } } ); }
/** * 内存溢出的话 可以找笔记 * @param context */ public static void initImageLoader(Context context,DisplayImageOptions defaultDisplayImageOptions,boolean writeDebugLogs) { // This configuration tuning is custom. You can tune every option, you may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. //路径是:/data/data/com.example.mylib_test/cache 要加image File cacheDir =new File(context.getCacheDir(),"images"); ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); /** ==========================线程方面 =========================*/ // 设置显示图片线程池大小,默认为3 config.threadPoolSize(3); // 设定线程等级比普通低一点 config.threadPriority(Thread.NORM_PRIORITY - 2); //设置用于加载和显示图像的任务的队列处理类型。 config.tasksProcessingOrder(QueueProcessingType.LIFO); /** ==========================内存缓存 =========================*/ //图片解码期间 中bitmap的宽高 默认是 手机宽高 那就默认了~ config.memoryCacheExtraOptions(480, 800); /** * memoryCache(...)和memoryCacheSize(...)这两个参数会互相覆盖,所以在ImageLoaderConfiguration中使用一个就好了 */ // 内存缓存的最大值 config.memoryCache(new LruMemoryCache(2 * 1024 * 1024)); //缓存到内存的最大数据 // config.memoryCacheSize(2 * 1024 * 1024); // 设定只保存同一尺寸的图片在内存 config.denyCacheImageMultipleSizesInMemory(); /** ==========================文件缓存 =========================*/ int[] screenParams=ScreenUtils.getScreenPixByResources(context); //下载图片后 compress保存到文件中的 宽高 config.diskCacheExtraOptions(screenParams[0], screenParams[1], null); /** * diskCacheSize(...)、diskCache(...)和diskCacheFileCount(...)这三个参数会互相覆盖,只使用一个 */ // 设定缓存的SDcard目录,UnlimitDiscCache速度最快 config.diskCache(new UnlimitedDiskCache(cacheDir)); //缓存到文件的最大数据 50 MiB config.diskCacheSize(50 * 1024 * 1024); //文件数量 //config.diskCacheFileCount(1000); // //将保存的时候的URI名称用MD5 加密 config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); //BaseImageDecoder true:打印log false:你懂的 config.imageDecoder(new BaseImageDecoder(true)); /** ==========================超时 与log打印 =========================*/ // 设定网络连接超时 timeout: 10s 读取网络连接超时read timeout: 45s config.imageDownloader(new BaseImageDownloader(context, 10000, 45000)); if (defaultDisplayImageOptions!=null) { //如果你的程序中使用displayImage()方法时传入的参数经常是一样的,那么一个合理的解决方法是一下 config.defaultDisplayImageOptions(defaultDisplayImageOptions); } if (writeDebugLogs) { //打印log config.writeDebugLogs(); // Remove for release app } // Initialize ImageLoader load configuration. ImageLoader.getInstance().init(config.build()); }
public static ImageDecoder createImageDecoder(boolean flag) { return new BaseImageDecoder(flag); }
private void initImageLoader() { DisplayImageOptions imageOptions = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_picture_loading) .showImageOnFail(R.drawable.ic_picture_loadfailed) .cacheInMemory(true).cacheOnDisk(true) .resetViewBeforeLoading(true).considerExifParams(false) .bitmapConfig(Bitmap.Config.RGB_565).build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( this) .memoryCacheExtraOptions(400, 400) // default = device screen dimensions .diskCacheExtraOptions(400, 400, null) .threadPoolSize(5) // default Thread.NORM_PRIORITY - 1 .threadPriority(Thread.NORM_PRIORITY) // default FIFO .tasksProcessingOrder(QueueProcessingType.LIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .diskCache( new UnlimitedDiscCache(StorageUtils.getCacheDirectory( this, true))) // default .diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(this)) // default .imageDecoder(new BaseImageDecoder(false)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .defaultDisplayImageOptions(imageOptions).build(); ImageLoader.getInstance().init(config); }