com.nostra13.universalimageloader.core.assist.ViewScaleType Java Examples

The following examples show how to use com.nostra13.universalimageloader.core.assist.ViewScaleType. 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: ImageDecodingInfo.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #2
Source File: ImageDecodingInfo.java    From candybar with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
                         ImageDownloader downloader, DisplayImageOptions displayOptions) {
    this.imageKey = imageKey;
    this.imageUri = imageUri;
    this.originalImageUri = originalImageUri;
    this.targetSize = targetSize;

    this.imageScaleType = displayOptions.getImageScaleType();
    this.viewScaleType = viewScaleType;

    this.downloader = downloader;
    this.extraForDownloader = displayOptions.getExtraForDownloader();

    considerExifParams = displayOptions.isConsiderExifParams();
    decodingOptions = new Options();
    copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #3
Source File: ImageDecodingInfo.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #4
Source File: ImageDecodingInfo.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #5
Source File: NonViewAware.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public NonViewAware(String s, ImageSize imagesize, ViewScaleType viewscaletype)
{
    if (imagesize == null)
    {
        throw new IllegalArgumentException("imageSize must not be null");
    }
    if (viewscaletype == null)
    {
        throw new IllegalArgumentException("scaleType must not be null");
    } else
    {
        imageUri = s;
        imageSize = imagesize;
        scaleType = viewscaletype;
        return;
    }
}
 
Example #6
Source File: LoadAndDisplayImageTask.java    From letv with Apache License 2.0 6 votes vote down vote up
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
    File targetFile = this.configuration.diskCache.get(this.uri);
    if (targetFile == null || !targetFile.exists()) {
        return false;
    }
    Bitmap bmp = this.decoder.decode(new ImageDecodingInfo(this.memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), this.uri, new ImageSize(maxWidth, maxHeight), ViewScaleType.FIT_INSIDE, getDownloader(), new Builder().cloneFrom(this.options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build()));
    if (!(bmp == null || this.configuration.processorForDiskCache == null)) {
        L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, this.memoryCacheKey);
        bmp = this.configuration.processorForDiskCache.process(bmp);
        if (bmp == null) {
            L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, this.memoryCacheKey);
        }
    }
    if (bmp == null) {
        return false;
    }
    boolean saved = this.configuration.diskCache.save(this.uri, bmp);
    bmp.recycle();
    return saved;
}
 
Example #7
Source File: ImageLoader.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public void loadImage(String s, ImageSize imagesize, DisplayImageOptions displayimageoptions, ImageLoadingListener imageloadinglistener, ImageLoadingProgressListener imageloadingprogresslistener)
{
    a();
    if (imagesize == null)
    {
        imagesize = h.a();
    }
    DisplayImageOptions displayimageoptions1;
    if (displayimageoptions == null)
    {
        displayimageoptions1 = h.r;
    } else
    {
        displayimageoptions1 = displayimageoptions;
    }
    displayImage(s, new NonViewAware(s, imagesize, ViewScaleType.CROP), displayimageoptions1, imageloadinglistener, imageloadingprogresslistener);
}
 
Example #8
Source File: ImageSizeUtils.java    From letv with Apache License 2.0 6 votes vote down vote up
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType, boolean stretch) {
    int destWidth;
    int srcWidth = srcSize.getWidth();
    int srcHeight = srcSize.getHeight();
    int targetWidth = targetSize.getWidth();
    int targetHeight = targetSize.getHeight();
    float widthScale = ((float) srcWidth) / ((float) targetWidth);
    float heightScale = ((float) srcHeight) / ((float) targetHeight);
    int destHeight;
    if ((viewScaleType != ViewScaleType.FIT_INSIDE || widthScale < heightScale) && (viewScaleType != ViewScaleType.CROP || widthScale >= heightScale)) {
        destWidth = (int) (((float) srcWidth) / heightScale);
        destHeight = targetHeight;
    } else {
        destWidth = targetWidth;
        destHeight = (int) (((float) srcHeight) / widthScale);
    }
    if ((stretch || destWidth >= srcWidth || destHeight >= srcHeight) && (!stretch || destWidth == srcWidth || destHeight == srcHeight)) {
        return 1.0f;
    }
    return ((float) destWidth) / ((float) srcWidth);
}
 
Example #9
Source File: ImageDecodingInfo.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #10
Source File: ImageViewAware.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
@Override
public ViewScaleType getScaleType() {
	ImageView imageView = (ImageView) viewRef.get();
	if (imageView != null) {
		return ViewScaleType.fromImageView(imageView);
	}
	return super.getScaleType();
}
 
Example #11
Source File: ImageLoader.java    From letv with Apache License 2.0 5 votes vote down vote up
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (targetImageSize == null) {
        targetImageSize = this.configuration.getMaxImageSize();
    }
    if (options == null) {
        options = this.configuration.defaultDisplayImageOptions;
    }
    displayImage(uri, new NonViewAware(uri, targetImageSize, ViewScaleType.CROP), options, listener, progressListener);
}
 
Example #12
Source File: NonViewAware.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
	if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null");
	if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null");

	this.imageUri = imageUri;
	this.imageSize = imageSize;
	this.scaleType = scaleType;
}
 
Example #13
Source File: LoadAndDisplayImageTask.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
/** Decodes image file into Bitmap, resize it and save it back */
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
	// Decode image file, compress and re-save it
	boolean saved = false;
	File targetFile = configuration.diskCache.get(uri);
	if (targetFile != null && targetFile.exists()) {
		ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight);
		DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options)
				.imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
		ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey,
				Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE,
				getDownloader(), specialOptions);
		Bitmap bmp = decoder.decode(decodingInfo);
		if (bmp != null && configuration.processorForDiskCache != null) {
			L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
			bmp = configuration.processorForDiskCache.process(bmp);
			if (bmp == null) {
				L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
			}
		}
		if (bmp != null) {
			saved = configuration.diskCache.save(uri, bmp);
			bmp.recycle();
		}
	}
	return saved;
}
 
Example #14
Source File: ImageSizeUtils.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Computes scale of target size (<b>targetSize</b>) to source size (<b>srcSize</b>).<br />
 * <br />
 * <b>Examples:</b><br />
 * <p/>
 * <pre>
 * srcSize(40x40), targetSize(10x10) -> scale = 0.25
 *
 * srcSize(10x10), targetSize(20x20), stretch = false -> scale = 1
 * srcSize(10x10), targetSize(20x20), stretch = true  -> scale = 2
 *
 * srcSize(100x100), targetSize(20x40), viewScaleType = FIT_INSIDE -> scale = 0.2
 * srcSize(100x100), targetSize(20x40), viewScaleType = CROP       -> scale = 0.4
 * </pre>
 *
 * @param srcSize       Source (image) size
 * @param targetSize    Target (view) size
 * @param viewScaleType {@linkplain ViewScaleType Scale type} for placing image in view
 * @param stretch       Whether source size should be stretched if target size is larger than source size. If <b>false</b>
 *                      then result scale value can't be greater than 1.
 * @return Computed scale
 */
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType,
		boolean stretch) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = targetSize.getWidth();
	final int targetHeight = targetSize.getHeight();

	final float widthScale = (float) srcWidth / targetWidth;
	final float heightScale = (float) srcHeight / targetHeight;

	final int destWidth;
	final int destHeight;
	if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) {
		destWidth = targetWidth;
		destHeight = (int) (srcHeight / widthScale);
	} else {
		destWidth = (int) (srcWidth / heightScale);
		destHeight = targetHeight;
	}

	float scale = 1;
	if ((!stretch && destWidth < srcWidth && destHeight < srcHeight) || (stretch && destWidth != srcWidth && destHeight != srcHeight)) {
		scale = (float) destWidth / srcWidth;
	}

	return scale;
}
 
Example #15
Source File: NonViewAware.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
	if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null");
	if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null");

	this.imageUri = imageUri;
	this.imageSize = imageSize;
	this.scaleType = scaleType;
}
 
Example #16
Source File: ImageViewAware.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public ViewScaleType getScaleType() {
	ImageView imageView = (ImageView) viewRef.get();
	if (imageView != null) {
		return ViewScaleType.fromImageView(imageView);
	}
	return super.getScaleType();
}
 
Example #17
Source File: NonViewAware.java    From letv with Apache License 2.0 5 votes vote down vote up
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
    if (imageSize == null) {
        throw new IllegalArgumentException("imageSize must not be null");
    } else if (scaleType == null) {
        throw new IllegalArgumentException("scaleType must not be null");
    } else {
        this.imageUri = imageUri;
        this.imageSize = imageSize;
        this.scaleType = scaleType;
    }
}
 
Example #18
Source File: NonViewAware.java    From candybar with Apache License 2.0 5 votes vote down vote up
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
    if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null");
    if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null");

    this.imageUri = imageUri;
    this.imageSize = imageSize;
    this.scaleType = scaleType;
}
 
Example #19
Source File: ImageLoader.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 * 添加图片加载任务到执行线程池中。图片会通过回调方法返回
 * @param uri                 图片URL地址
 * @param targetImageSize     期望目标图片大小尺寸
 * @param options             图片配置项
 * @param listener            图片加载监听器
 * @param progressListener    图片下载进度监听器
 */
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options,
		ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
	checkConfiguration();
	if (targetImageSize == null) {
		targetImageSize = configuration.getMaxImageSize();
	}
	if (options == null) {
		options = configuration.defaultDisplayImageOptions;
	}

	NonViewAware imageAware = new NonViewAware(uri, targetImageSize, ViewScaleType.CROP);
	displayImage(uri, imageAware, options, listener, progressListener);
}
 
Example #20
Source File: NonViewAware.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
	if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null");
	if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null");

	this.imageUri = imageUri;
	this.imageSize = imageSize;
	this.scaleType = scaleType;
}
 
Example #21
Source File: ImageSizeUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Computes scale of target size (<b>targetSize</b>) to source size (<b>srcSize</b>).<br />
 * <br />
 * <b>Examples:</b><br />
 * <p/>
 * <pre>
 * srcSize(40x40), targetSize(10x10) -> scale = 0.25
 *
 * srcSize(10x10), targetSize(20x20), stretch = false -> scale = 1
 * srcSize(10x10), targetSize(20x20), stretch = true  -> scale = 2
 *
 * srcSize(100x100), targetSize(20x40), viewScaleType = FIT_INSIDE -> scale = 0.2
 * srcSize(100x100), targetSize(20x40), viewScaleType = CROP       -> scale = 0.4
 * </pre>
 *
 * @param srcSize       Source (image) size
 * @param targetSize    Target (view) size
 * @param viewScaleType {@linkplain ViewScaleType Scale type} for placing image in view
 * @param stretch       Whether source size should be stretched if target size is larger than source size. If <b>false</b>
 *                      then result scale value can't be greater than 1.
 * @return Computed scale
 */
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType,
		boolean stretch) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = targetSize.getWidth();
	final int targetHeight = targetSize.getHeight();

	final float widthScale = (float) srcWidth / targetWidth;
	final float heightScale = (float) srcHeight / targetHeight;

	final int destWidth;
	final int destHeight;
	if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) {
		destWidth = targetWidth;
		destHeight = (int) (srcHeight / widthScale);
	} else {
		destWidth = (int) (srcWidth / heightScale);
		destHeight = targetHeight;
	}

	float scale = 1;
	if ((!stretch && destWidth < srcWidth && destHeight < srcHeight) || (stretch && destWidth != srcWidth && destHeight != srcHeight)) {
		scale = (float) destWidth / srcWidth;
	}

	return scale;
}
 
Example #22
Source File: ImageViewAware.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
@Override
public ViewScaleType getScaleType() {
	ImageView imageView = (ImageView) viewRef.get();
	if (imageView != null) {
		return ViewScaleType.fromImageView(imageView);
	}
	return super.getScaleType();
}
 
Example #23
Source File: NonViewAware.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
	if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null");
	if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null");

	this.imageUri = imageUri;
	this.imageSize = imageSize;
	this.scaleType = scaleType;
}
 
Example #24
Source File: ImageSizeUtils.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public static float computeImageScale(ImageSize imagesize, ImageSize imagesize1, ViewScaleType viewscaletype, boolean flag)
{
    int i = imagesize.getWidth();
    int j = imagesize.getHeight();
    int k = imagesize1.getWidth();
    int l = imagesize1.getHeight();
    float f = (float)i / (float)k;
    float f1 = (float)j / (float)l;
    int i1;
    int j1;
    float f2;
    if (viewscaletype == ViewScaleType.FIT_INSIDE && f >= f1 || viewscaletype == ViewScaleType.CROP && f < f1)
    {
        int k1 = (int)((float)j / f);
        i1 = k;
        j1 = k1;
    } else
    {
        i1 = (int)((float)i / f1);
        j1 = l;
    }
    f2 = 1.0F;
    if (!flag && i1 < i && j1 < j || flag && i1 != i && j1 != j)
    {
        f2 = (float)i1 / (float)i;
    }
    return f2;
}
 
Example #25
Source File: ImageDecodingInfo.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public ImageDecodingInfo(String s, String s1, String s2, ImageSize imagesize, ViewScaleType viewscaletype, ImageDownloader imagedownloader, DisplayImageOptions displayimageoptions)
{
    a = s;
    b = s1;
    c = s2;
    d = imagesize;
    e = displayimageoptions.getImageScaleType();
    f = viewscaletype;
    g = imagedownloader;
    h = displayimageoptions.getExtraForDownloader();
    i = displayimageoptions.isConsiderExifParams();
    a(displayimageoptions.getDecodingOptions(), j);
}
 
Example #26
Source File: ImageViewAware.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public ViewScaleType getScaleType()
{
    ImageView imageview = (ImageView)viewRef.get();
    if (imageview != null)
    {
        return ViewScaleType.fromImageView(imageview);
    } else
    {
        return super.getScaleType();
    }
}
 
Example #27
Source File: ImageSizeUtils.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 * Computes scale of target size (<b>targetSize</b>) to source size (<b>srcSize</b>).<br />
 * <br />
 * <b>Examples:</b><br />
 * <p/>
 * <pre>
 * srcSize(40x40), targetSize(10x10) -> scale = 0.25
 *
 * srcSize(10x10), targetSize(20x20), stretch = false -> scale = 1
 * srcSize(10x10), targetSize(20x20), stretch = true  -> scale = 2
 *
 * srcSize(100x100), targetSize(20x40), viewScaleType = FIT_INSIDE -> scale = 0.2
 * srcSize(100x100), targetSize(20x40), viewScaleType = CROP       -> scale = 0.4
 * </pre>
 *
 * @param srcSize       Source (image) size
 * @param targetSize    Target (view) size
 * @param viewScaleType {@linkplain ViewScaleType Scale type} for placing image in view
 * @param stretch       Whether source size should be stretched if target size is larger than source size. If <b>false</b>
 *                      then result scale value can't be greater than 1.
 * @return Computed scale
 */
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType,
		boolean stretch) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = targetSize.getWidth();
	final int targetHeight = targetSize.getHeight();

	final float widthScale = (float) srcWidth / targetWidth;
	final float heightScale = (float) srcHeight / targetHeight;

	final int destWidth;
	final int destHeight;
	if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) {
		destWidth = targetWidth;
		destHeight = (int) (srcHeight / widthScale);
	} else {
		destWidth = (int) (srcWidth / heightScale);
		destHeight = targetHeight;
	}

	float scale = 1;
	if ((!stretch && destWidth < srcWidth && destHeight < srcHeight) || (stretch && destWidth != srcWidth && destHeight != srcHeight)) {
		scale = (float) destWidth / srcWidth;
	}

	return scale;
}
 
Example #28
Source File: LoadAndDisplayImageTask.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 * 根据图片资源地址进行解码图片
 * @param imageUri   图片资源地址
 * @return
 * @throws IOException
 */
private Bitmap decodeImage(String imageUri) throws IOException {
	ViewScaleType viewScaleType = imageAware.getScaleType();
	ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, imageUri, uri, targetSize, viewScaleType,
			getDownloader(), options);
	return decoder.decode(decodingInfo);
}
 
Example #29
Source File: LoadAndDisplayImageTask.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 * Decodes image file into Bitmap, resize it and save it back
 * 解码图片 进行图片尺寸修改,然后保存
 */
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
	// Decode image file, compress and re-save it
	boolean saved = false;
	File targetFile = configuration.diskCache.get(uri);
	if (targetFile != null && targetFile.exists()) {
		//构建图片尺寸size对象
		ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight);
		//图片显示配置参数构建
		DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options)
				.imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
		ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey,
				Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE,
				getDownloader(), specialOptions);
		//获取解码之后的图片
		Bitmap bmp = decoder.decode(decodingInfo);
		if (bmp != null && configuration.processorForDiskCache != null) {
			L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
			bmp = configuration.processorForDiskCache.process(bmp);
			if (bmp == null) {
				L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
			}
		}
		if (bmp != null) {
			//图片重新保存本地文件系统
			saved = configuration.diskCache.save(uri, bmp);
			bmp.recycle();
		}
	}
	return saved;
}
 
Example #30
Source File: ImageSizeUtils.java    From candybar with Apache License 2.0 5 votes vote down vote up
/**
 * Computes scale of target size (<b>targetSize</b>) to source size (<b>srcSize</b>).<br />
 * <br />
 * <b>Examples:</b><br />
 * <p/>
 * <pre>
 * srcSize(40x40), targetSize(10x10) -> scale = 0.25
 *
 * srcSize(10x10), targetSize(20x20), stretch = false -> scale = 1
 * srcSize(10x10), targetSize(20x20), stretch = true  -> scale = 2
 *
 * srcSize(100x100), targetSize(20x40), viewScaleType = FIT_INSIDE -> scale = 0.2
 * srcSize(100x100), targetSize(20x40), viewScaleType = CROP       -> scale = 0.4
 * </pre>
 *
 * @param srcSize       Source (image) size
 * @param targetSize    Target (view) size
 * @param viewScaleType {@linkplain ViewScaleType Scale type} for placing image in view
 * @param stretch       Whether source size should be stretched if target size is larger than source size. If <b>false</b>
 *                      then result scale value can't be greater than 1.
 * @return Computed scale
 */
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType,
                                      boolean stretch) {
    final int srcWidth = srcSize.getWidth();
    final int srcHeight = srcSize.getHeight();
    final int targetWidth = targetSize.getWidth();
    final int targetHeight = targetSize.getHeight();

    final float widthScale = (float) srcWidth / targetWidth;
    final float heightScale = (float) srcHeight / targetHeight;

    final int destWidth;
    final int destHeight;
    if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) {
        destWidth = targetWidth;
        destHeight = (int) (srcHeight / widthScale);
    } else {
        destWidth = (int) (srcWidth / heightScale);
        destHeight = targetHeight;
    }

    float scale = 1;
    if ((!stretch && destWidth < srcWidth && destHeight < srcHeight) || (stretch && destWidth != srcWidth && destHeight != srcHeight)) {
        scale = (float) destWidth / srcWidth;
    }

    return scale;
}