Java Code Examples for com.nostra13.universalimageloader.core.assist.ImageSize#getHeight()

The following examples show how to use com.nostra13.universalimageloader.core.assist.ImageSize#getHeight() . 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: 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 2
Source File: ImageSizeUtils.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
/**
 * Defines target size for image aware view. Size is defined by target
 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration
 * parameters or device display dimensions.<br />
 */
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
    int width = imageAware.getWidth();
    if (width <= 0) width = maxImageSize.getWidth();

    int height = imageAware.getHeight();
    if (height <= 0) height = maxImageSize.getHeight();

    return new ImageSize(width, height);
}
 
Example 3
Source File: ImageSizeUtils.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
/**
 * Defines target size for image aware view. Size is defined by target
 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration
 * parameters or device display dimensions.<br />
 */
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
	int width = imageAware.getWidth();
	if (width <= 0) width = maxImageSize.getWidth();

	int height = imageAware.getHeight();
	if (height <= 0) height = maxImageSize.getHeight();

	return new ImageSize(width, height);
}
 
Example 4
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 5
Source File: ImageSizeUtils.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Computes minimal sample size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal sample size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal sample size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = maxBitmapSize.getWidth();
	final int targetHeight = maxBitmapSize.getHeight();

	final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
	final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

	return Math.max(widthScale, heightScale); // max
}
 
Example 6
Source File: ImageSizeUtils.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Defines target size for image aware view. Size is defined by target
 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration
 * parameters or device display dimensions.<br />
 */
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
	int width = imageAware.getWidth();
	if (width <= 0) width = maxImageSize.getWidth();

	int height = imageAware.getHeight();
	if (height <= 0) height = maxImageSize.getHeight();

	return new ImageSize(width, height);
}
 
Example 7
Source File: ImageSizeUtils.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 * 给显示的控件定义目标大小
 * Defines target size for image aware view. Size is defined by target
 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration
 * parameters or device display dimensions.<br />
 */
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
	int width = imageAware.getWidth();
	if (width <= 0) width = maxImageSize.getWidth();

	int height = imageAware.getHeight();
	if (height <= 0) height = maxImageSize.getHeight();

	return new ImageSize(width, height);
}
 
Example 8
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 9
Source File: ImageSizeUtils.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
/**
 * Defines target size for image aware view. Size is defined by target
 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration
 * parameters or device display dimensions.<br />
 */
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
	int width = imageAware.getWidth();
	if (width <= 0) width = maxImageSize.getWidth();

	int height = imageAware.getHeight();
	if (height <= 0) height = maxImageSize.getHeight();

	return new ImageSize(width, height);
}
 
Example 10
Source File: ImageSizeUtils.java    From Yahala-Messenger with MIT License 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 11
Source File: ImageSizeUtils.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
/**
 * Computes minimal sample size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal sample size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal sample size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
    final int srcWidth = srcSize.getWidth();
    final int srcHeight = srcSize.getHeight();
    final int targetWidth = maxBitmapSize.getWidth();
    final int targetHeight = maxBitmapSize.getHeight();

    final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
    final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

    return Math.max(widthScale, heightScale); // max
}
 
Example 12
Source File: ImageSizeUtils.java    From candybar with Apache License 2.0 5 votes vote down vote up
/**
 * Defines target size for image aware view. Size is defined by target
 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration
 * parameters or device display dimensions.<br />
 */
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
    int width = imageAware.getWidth();
    if (width <= 0) width = maxImageSize.getWidth();

    int height = imageAware.getHeight();
    if (height <= 0) height = maxImageSize.getHeight();

    return new ImageSize(width, height);
}
 
Example 13
Source File: ImageSizeUtils.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public static ImageSize defineTargetSizeForView(ImageAware imageaware, ImageSize imagesize)
{
    int i = imageaware.getWidth();
    if (i <= 0)
    {
        i = imagesize.getWidth();
    }
    int j = imageaware.getHeight();
    if (j <= 0)
    {
        j = imagesize.getHeight();
    }
    return new ImageSize(i, j);
}
 
Example 14
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 15
Source File: ImageSizeUtils.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
/**
 * Computes minimal sample size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal sample size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal sample size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = maxBitmapSize.getWidth();
	final int targetHeight = maxBitmapSize.getHeight();

	final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
	final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

	return Math.max(widthScale, heightScale); // max
}
 
Example 16
Source File: ImageSizeUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static int computeImageSampleSize(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType, boolean powerOf2Scale) {
    int srcWidth = srcSize.getWidth();
    int srcHeight = srcSize.getHeight();
    int targetWidth = targetSize.getWidth();
    int targetHeight = targetSize.getHeight();
    int scale = 1;
    int halfWidth;
    int halfHeight;
    switch (viewScaleType) {
        case FIT_INSIDE:
            if (!powerOf2Scale) {
                scale = Math.max(srcWidth / targetWidth, srcHeight / targetHeight);
                break;
            }
            halfWidth = srcWidth / 2;
            halfHeight = srcHeight / 2;
            while (true) {
                if (halfWidth / scale <= targetWidth && halfHeight / scale <= targetHeight) {
                    break;
                }
                scale *= 2;
            }
            break;
        case CROP:
            if (!powerOf2Scale) {
                scale = Math.min(srcWidth / targetWidth, srcHeight / targetHeight);
                break;
            }
            halfWidth = srcWidth / 2;
            halfHeight = srcHeight / 2;
            while (halfWidth / scale > targetWidth && halfHeight / scale > targetHeight) {
                scale *= 2;
            }
            break;
    }
    if (scale < 1) {
        scale = 1;
    }
    return considerMaxTextureSize(srcWidth, srcHeight, scale, powerOf2Scale);
}
 
Example 17
Source File: ImageSizeUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
    int width = imageAware.getWidth();
    if (width <= 0) {
        width = maxImageSize.getWidth();
    }
    int height = imageAware.getHeight();
    if (height <= 0) {
        height = maxImageSize.getHeight();
    }
    return new ImageSize(width, height);
}
 
Example 18
Source File: ImageSizeUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Computes minimal sample size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal sample size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal sample size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = maxBitmapSize.getWidth();
	final int targetHeight = maxBitmapSize.getHeight();

	final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
	final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

	return Math.max(widthScale, heightScale); // max
}
 
Example 19
Source File: ImageSizeUtils.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public static int computeMinImageSampleSize(ImageSize imagesize)
{
    int i = imagesize.getWidth();
    int j = imagesize.getHeight();
    int k = b.getWidth();
    int l = b.getHeight();
    return Math.max((int)Math.ceil((float)i / (float)k), (int)Math.ceil((float)j / (float)l));
}
 
Example 20
Source File: ImageSizeUtils.java    From candybar with Apache License 2.0 5 votes vote down vote up
/**
 * Computes minimal dev size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal dev size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal dev size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
    final int srcWidth = srcSize.getWidth();
    final int srcHeight = srcSize.getHeight();
    final int targetWidth = maxBitmapSize.getWidth();
    final int targetHeight = maxBitmapSize.getHeight();

    final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
    final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

    return Math.max(widthScale, heightScale); // max
}