com.lidroid.xutils.bitmap.BitmapDisplayConfig Java Examples
The following examples show how to use
com.lidroid.xutils.bitmap.BitmapDisplayConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BitmapUtil.java From QiQuYing with Apache License 2.0 | 6 votes |
/** * 从缓存中获取原图 * @param uri * @return */ public static Bitmap getBitmapFromCache(String uri) { BitmapDisplayConfig config = new BitmapDisplayConfig(); config.setBitmapConfig(Bitmap.Config.ARGB_8888); config.setShowOriginal(true); Bitmap bitmap = mBitmapUtils.getBitmapFromMemCache(uri, config); if(bitmap != null) { return bitmap; } try { return BitmapFactory.decodeStream(new FileInputStream(mBitmapUtils.getBitmapFileFromDiskCache(uri))); } catch (FileNotFoundException e) { Log.e("getBitmapFileFromCache", "get bitmap error", e); } return null; }
Example #2
Source File: BitmapCache.java From android-open-project-demo with Apache License 2.0 | 5 votes |
private Bitmap addBitmapToMemoryCache(String uri, BitmapDisplayConfig config, Bitmap bitmap, long expiryTimestamp) throws IOException { if (config != null) { BitmapFactory bitmapFactory = config.getBitmapFactory(); if (bitmapFactory != null) { bitmap = bitmapFactory.cloneNew().createBitmap(bitmap); } } if (uri != null && bitmap != null && globalConfig.isMemoryCacheEnabled() && mMemoryCache != null) { MemoryCacheKey key = new MemoryCacheKey(uri, config); mMemoryCache.put(key, bitmap, expiryTimestamp); } return bitmap; }
Example #3
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public BitmapLoadTask(T container, String uri, BitmapDisplayConfig config, BitmapLoadCallBack<T> callBack) { if (container == null || uri == null || config == null || callBack == null) { throw new IllegalArgumentException("args may not be null"); } this.containerReference = new WeakReference<T>(container); this.callBack = callBack; this.uri = uri; this.displayConfig = config; }
Example #4
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public BitmapUtils(Context context, String diskCachePath) { if (context == null) { throw new IllegalArgumentException("context may not be null"); } this.context = context.getApplicationContext(); globalConfig = BitmapGlobalConfig.getInstance(this.context, diskCachePath); defaultDisplayConfig = new BitmapDisplayConfig(); }
Example #5
Source File: BitmapCache.java From android-open-project-demo with Apache License 2.0 | 5 votes |
/** * 流转化为bitmap, 而且根据config压缩图片 * @param bitmapMeta * @param config * @return * @throws IOException */ private Bitmap decodeBitmapMeta(BitmapMeta bitmapMeta, BitmapDisplayConfig config) throws IOException { if (bitmapMeta == null) return null; Bitmap bitmap = null; if (bitmapMeta.inputStream != null) { //BitmapFromDescriptor这一块使用的是这个方法而不是直接用流, 在网上找了一些 //资料, 这种转化能避免一些莫名其妙的图片加载不出来的问题 if (config == null || config.isShowOriginal()) { //原图 bitmap = BitmapDecoder.decodeFileDescriptor(bitmapMeta.inputStream.getFD()); } else { //压缩图 bitmap = BitmapDecoder.decodeSampledBitmapFromDescriptor( bitmapMeta.inputStream.getFD(), config.getBitmapMaxSize(), config.getBitmapConfig()); } } else if (bitmapMeta.data != null) { if (config == null || config.isShowOriginal()) { bitmap = BitmapDecoder.decodeByteArray(bitmapMeta.data); } else { bitmap = BitmapDecoder.decodeSampledBitmapFromByteArray( bitmapMeta.data, config.getBitmapMaxSize(), config.getBitmapConfig()); } } return bitmap; }
Example #6
Source File: BitmapCache.java From android-open-project-demo with Apache License 2.0 | 5 votes |
/** * Get the bitmap from disk cache. * * @param uri * @param config * @return */ public Bitmap getBitmapFromDiskCache(String uri, BitmapDisplayConfig config) { if (uri == null || !globalConfig.isDiskCacheEnabled()) return null; if (mDiskLruCache == null) { initDiskCache(); } if (mDiskLruCache != null) { LruDiskCache.Snapshot snapshot = null; try { snapshot = mDiskLruCache.get(uri); if (snapshot != null) { Bitmap bitmap = null; if (config == null || config.isShowOriginal()) { bitmap = BitmapDecoder.decodeFileDescriptor( snapshot.getInputStream(DISK_CACHE_INDEX).getFD()); } else { bitmap = BitmapDecoder.decodeSampledBitmapFromDescriptor( snapshot.getInputStream(DISK_CACHE_INDEX).getFD(), config.getBitmapMaxSize(), config.getBitmapConfig()); } bitmap = rotateBitmapIfNeeded(uri, config, bitmap); bitmap = addBitmapToMemoryCache(uri, config, bitmap, mDiskLruCache.getExpiryTimestamp(uri)); return bitmap; } } catch (Throwable e) { LogUtils.e(e.getMessage(), e); } finally { IOUtils.closeQuietly(snapshot); } } return null; }
Example #7
Source File: BitmapCache.java From android-open-project-demo with Apache License 2.0 | 5 votes |
/** * Get the bitmap from memory cache. * * @param uri Unique identifier for which item to get * @param config * @return The bitmap if found in cache, null otherwise */ public Bitmap getBitmapFromMemCache(String uri, BitmapDisplayConfig config) { if (mMemoryCache != null && globalConfig.isMemoryCacheEnabled()) { MemoryCacheKey key = new MemoryCacheKey(uri, config); return mMemoryCache.get(key); } return null; }
Example #8
Source File: PercentImageViewLoadCallBack.java From QiQuYing with Apache License 2.0 | 5 votes |
@Override public void onLoadCompleted(ImageView arg0, String arg1, Bitmap arg2, BitmapDisplayConfig arg3, BitmapLoadFrom arg4) { LoadPercentImageView imageView = (LoadPercentImageView)arg0; imageView.setProgress(100); imageView.setComplete(true); imageView.setImageBitmap(arg2); }
Example #9
Source File: DefaultBitmapLoadCallBack.java From android-open-project-demo with Apache License 2.0 | 5 votes |
@Override public void onLoadCompleted(T container, String uri, Bitmap bitmap, BitmapDisplayConfig config, BitmapLoadFrom from) { this.setBitmap(container, bitmap); Animation animation = config.getAnimation(); if (animation != null) { animationDisplay(container, animation); } }
Example #10
Source File: XUtils2ImageLoader.java From GalleryFinal with Apache License 2.0 | 5 votes |
@Override public void displayImage(Activity activity, String path, GFImageView imageView, Drawable defaultDrawable, int width, int height) { BitmapDisplayConfig config = new BitmapDisplayConfig(); config.setLoadFailedDrawable(defaultDrawable); config.setLoadingDrawable(defaultDrawable); config.setBitmapConfig(Bitmap.Config.RGB_565); config.setBitmapMaxSize(new BitmapSize(width, height)); bitmapUtils.display(imageView, "file://" + path, config); }
Example #11
Source File: PercentImageViewLoadCallBack.java From QiQuYing with Apache License 2.0 | 5 votes |
@Override public void onLoading(ImageView arg0, String uri, BitmapDisplayConfig config, long total, long current) { // super.onLoading(arg0, uri, config, total, current); LoadPercentImageView imageView = (LoadPercentImageView)arg0; int progress = (int)(((double)current) / ((double)total) * 100); imageView.setProgress(progress); }
Example #12
Source File: BitmapCache.java From android-open-project-demo with Apache License 2.0 | 4 votes |
private MemoryCacheKey(String uri, BitmapDisplayConfig config) { this.uri = uri; this.subKey = config == null ? null : config.toString(); }
Example #13
Source File: BitmapUtil.java From QiQuYing with Apache License 2.0 | 4 votes |
/** * 获取缓存中图片的缩略图 * @param uri * @return */ public static Bitmap getThumbBitmapFromCache(String uri, int width, int height) { BitmapDisplayConfig config = new BitmapDisplayConfig(); config.setBitmapConfig(Bitmap.Config.ARGB_8888); config.setShowOriginal(false); BitmapSize bitmapSize = new BitmapSize(width, height); config.setBitmapMaxSize(bitmapSize); Bitmap bitmap = mBitmapUtils.getBitmapFromMemCache(uri, config); if(bitmap != null) { return bitmap; } try { // Bitmap bitmap2 = BitmapFactory.decodeStream(new FileInputStream()); File file = mBitmapUtils.getBitmapFileFromDiskCache(uri); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; // 获取这个图片的宽和高,注意此处的bitmap为null bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); options.inJustDecodeBounds = false; // 设为 false // 计算缩放比 int h = options.outHeight; int w = options.outWidth; int beWidth = w / width; int beHeight = h / height; int be = 1; if (beWidth < beHeight) { be = beWidth; } else { be = beHeight; } if (be <= 0) { be = 1; } options.inSampleSize = be; // 重新读入图片,读取缩放后的bitmap,注意这次要把options.inJustDecodeBounds 设为 false bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); // 利用ThumbnailUtils来创建缩略图,这里要指定要缩放哪个Bitmap对象 bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; } catch (Exception e) { Log.e("getBitmapFileFromCache", "get bitmap error", e); } return null; }
Example #14
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 4 votes |
public BitmapUtils configDefaultDisplayConfig(BitmapDisplayConfig displayConfig) { defaultDisplayConfig = displayConfig; return this; }
Example #15
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 4 votes |
public <T extends View> void display(T container, String uri, BitmapDisplayConfig displayConfig) { display(container, uri, displayConfig, null); }
Example #16
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 4 votes |
public <T extends View> void display(T container, String uri, BitmapDisplayConfig displayConfig, BitmapLoadCallBack<T> callBack) { if (container == null) { return; } if (callBack == null) { callBack = new DefaultBitmapLoadCallBack<T>(); //默认的回调 } if (displayConfig == null || displayConfig == defaultDisplayConfig) { displayConfig = defaultDisplayConfig.cloneNew();// 默认展示图片的设置 } // Optimize Max Size BitmapSize size = displayConfig.getBitmapMaxSize(); //配置显示控件的大小 displayConfig.setBitmapMaxSize(BitmapCommonUtils.optimizeMaxSizeByView(container, size.getWidth(), size.getHeight())); container.clearAnimation(); if (TextUtils.isEmpty(uri)) { callBack.onLoadFailed(container, uri, displayConfig.getLoadFailedDrawable()); return; } // start loading callBack.onPreLoad(container, uri, displayConfig); // find bitmap from mem cache. 优先从运行内存的缓存中读取 Bitmap bitmap = globalConfig.getBitmapCache().getBitmapFromMemCache(uri, displayConfig); if (bitmap != null) { callBack.onLoadStarted(container, uri, displayConfig); callBack.onLoadCompleted( container, uri, bitmap, displayConfig, BitmapLoadFrom.MEMORY_CACHE); } else if (!bitmapLoadTaskExist(container, uri, callBack)) { //这里判断任务是否正在加载中 final BitmapLoadTask<T> loadTask = new BitmapLoadTask<T>(container, uri, displayConfig, callBack); // get executor PriorityExecutor executor = globalConfig.getBitmapLoadExecutor(); File diskCacheFile = this.getBitmapFileFromDiskCache(uri); boolean diskCacheExist = diskCacheFile != null && diskCacheFile.exists(); if (diskCacheExist && executor.isBusy()) { //如果闪存中有缓存,而且BitmapLoadExecutor线程池不够用就使用DiskCacheExecutor的线程池 executor = globalConfig.getDiskCacheExecutor(); } // set loading image Drawable loadingDrawable = displayConfig.getLoadingDrawable(); callBack.setDrawable(container, new AsyncDrawable<T>(loadingDrawable, loadTask)); loadTask.setPriority(displayConfig.getPriority()); loadTask.executeOnExecutor(executor); } }
Example #17
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 4 votes |
public Bitmap getBitmapFromMemCache(String uri, BitmapDisplayConfig config) { if (config == null) { config = defaultDisplayConfig; } return globalConfig.getBitmapCache().getBitmapFromMemCache(uri, config); }
Example #18
Source File: BitmapLoadCallBack.java From android-open-project-demo with Apache License 2.0 | 2 votes |
/** * Call back when loading. * * @param container * @param uri * @param config * @param total * @param current */ public void onLoading(T container, String uri, BitmapDisplayConfig config, long total, long current) { }
Example #19
Source File: BitmapLoadCallBack.java From android-open-project-demo with Apache License 2.0 | 2 votes |
/** * Call back when bitmap has loaded. * * @param container * @param uri * @param bitmap * @param config */ public abstract void onLoadCompleted(T container, String uri, Bitmap bitmap, BitmapDisplayConfig config, BitmapLoadFrom from);
Example #20
Source File: BitmapLoadCallBack.java From android-open-project-demo with Apache License 2.0 | 2 votes |
/** * Call back when start loading. * * @param container * @param uri * @param config */ public void onLoadStarted(T container, String uri, BitmapDisplayConfig config) { }
Example #21
Source File: BitmapLoadCallBack.java From android-open-project-demo with Apache License 2.0 | 2 votes |
/** * Call back when start loading. * * @param container * @param uri * @param config */ public void onPreLoad(T container, String uri, BitmapDisplayConfig config) { }