com.lidroid.xutils.bitmap.core.BitmapSize Java Examples

The following examples show how to use com.lidroid.xutils.bitmap.core.BitmapSize. 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: XUtils2ImageLoader.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
@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 #2
Source File: BitmapCommonUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * @param view
 * @param maxImageWidth
 * @param maxImageHeight
 * 设置显示View的大小
 * @return
 */
public static BitmapSize optimizeMaxSizeByView(View view, int maxImageWidth, int maxImageHeight) {
    int width = maxImageWidth;
    int height = maxImageHeight;

    if (width > 0 && height > 0) { //当设置不为0的时候
        return new BitmapSize(width, height);
    }

    final ViewGroup.LayoutParams params = view.getLayoutParams(); 
    if (params != null) { 
        if (params.width > 0) {  //如果布局文件中配置了大小
            width = params.width;
        } else if (params.width != ViewGroup.LayoutParams.WRAP_CONTENT) {
            width = view.getWidth();
        }

        if (params.height > 0) {
            height = params.height;
        } else if (params.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
            height = view.getHeight();
        }
    }

    if (width <= 0) width = getImageViewFieldValue(view, "mMaxWidth");
    if (height <= 0) height = getImageViewFieldValue(view, "mMaxHeight");

    BitmapSize screenSize = getScreenSize(view.getContext());
    if (width <= 0) width = screenSize.getWidth();
    if (height <= 0) height = screenSize.getHeight();

    return new BitmapSize(width, height);
}
 
Example #3
Source File: BitmapUtil.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
/**
	 * 获取缓存中图片的缩略图
	 * @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 #4
Source File: BitmapDisplayConfig.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public BitmapSize getBitmapMaxSize() {
    return bitmapMaxSize == null ? BitmapSize.ZERO : bitmapMaxSize;
}
 
Example #5
Source File: BitmapDisplayConfig.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public void setBitmapMaxSize(BitmapSize bitmapMaxSize) {
    this.bitmapMaxSize = bitmapMaxSize;
}
 
Example #6
Source File: BitmapUtils.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public BitmapUtils configDefaultBitmapMaxSize(int maxWidth, int maxHeight) {
    defaultDisplayConfig.setBitmapMaxSize(new BitmapSize(maxWidth, maxHeight));
    return this;
}
 
Example #7
Source File: BitmapUtils.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public BitmapUtils configDefaultBitmapMaxSize(BitmapSize maxSize) {
    defaultDisplayConfig.setBitmapMaxSize(maxSize);
    return this;
}
 
Example #8
Source File: BitmapUtils.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
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);
    }
}