Java Code Examples for com.nostra13.universalimageloader.utils.ImageSizeUtils

The following examples show how to use com.nostra13.universalimageloader.utils.ImageSizeUtils. These examples are extracted from open source projects. 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 Project: candybar   Source File: BaseImageDecoder.java    License: Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }

    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example 2
Source Project: letv   Source File: BaseImageDecoder.java    License: Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    int scale;
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        boolean powerOf2;
        ImageSize targetSize = decodingInfo.getTargetSize();
        if (scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2) {
            powerOf2 = true;
        } else {
            powerOf2 = false;
        }
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && this.loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), Integer.valueOf(scale), decodingInfo.getImageKey());
    }
    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example 3
Source Project: talk-android   Source File: VideoRow.java    License: MIT License 6 votes vote down vote up
Bitmap tryLoadBitmap(ImageViewAware imageAware) {
    Bitmap bitmap = null;
    try {
        java.io.File imageFile = diskCache.get(getMessage().get_id());
        if (imageFile != null && imageFile.exists() && imageFile.length() > 0) {
            ViewScaleType viewScaleType = imageAware.getScaleType();
            ImageSize imageSize = ImageSizeUtils.defineTargetSizeForView(imageAware, new ImageSize(MainApp.CONTEXT.getResources().getDisplayMetrics().widthPixels, MainApp.CONTEXT.getResources().getDisplayMetrics().heightPixels));
            ImageDecodingInfo decodingInfo = new ImageDecodingInfo(getMessage().get_id(),
                    ImageDownloader.Scheme.FILE.wrap(imageFile.getAbsolutePath()), getMessage().get_id(), imageSize, viewScaleType,
                    new BaseImageDownloader(MainApp.CONTEXT), options);
            bitmap = decoder.decode(decodingInfo);
            MainApp.memoryCache.put(getMessage().get_id(), bitmap);
        }
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
    return bitmap;
}
 
Example 4
Source Project: talk-android   Source File: DiskDecoder.java    License: MIT License 6 votes vote down vote up
protected BitmapFactory.Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }

    BitmapFactory.Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example 5
Source Project: mobile-manager-tool   Source File: BaseImageDecoder.java    License: MIT License 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	int scale;
	if (scaleType == ImageScaleType.NONE) {
		scale = 1;
	} else if (scaleType == ImageScaleType.NONE_SAFE) {
		scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
	} else {
		ImageSize targetSize = decodingInfo.getTargetSize();
		boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
		scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
	}
	if (scale > 1 && loggingEnabled) {
		L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
	}

	Options decodingOptions = decodingInfo.getDecodingOptions();
	decodingOptions.inSampleSize = scale;
	return decodingOptions;
}
 
Example 6
Source Project: BigApp_WordPress_Android   Source File: BaseImageDecoder.java    License: Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }

    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example 7
Source Project: WliveTV   Source File: BaseImageDecoder.java    License: Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	int scale;
	if (scaleType == ImageScaleType.NONE) {
		scale = 1;
	} else if (scaleType == ImageScaleType.NONE_SAFE) {
		scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
	} else {
		ImageSize targetSize = decodingInfo.getTargetSize();
		boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
		scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
	}
	if (scale > 1 && loggingEnabled) {
		L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
	}

	Options decodingOptions = decodingInfo.getDecodingOptions();
	decodingOptions.inSampleSize = scale;
	return decodingOptions;
}
 
Example 8
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	int scale;
	if (scaleType == ImageScaleType.NONE) {
		scale = 1;
	} else if (scaleType == ImageScaleType.NONE_SAFE) {
		scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
	} else {
		ImageSize targetSize = decodingInfo.getTargetSize();
		boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
		scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
	}
	if (scale > 1 && loggingEnabled) {
		L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
	}

	Options decodingOptions = decodingInfo.getDecodingOptions();
	decodingOptions.inSampleSize = scale;
	return decodingOptions;
}
 
Example 9
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	int scale;
	if (scaleType == ImageScaleType.NONE) {
		scale = 1;
	} else if (scaleType == ImageScaleType.NONE_SAFE) {
		scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
	} else {
		ImageSize targetSize = decodingInfo.getTargetSize();
		boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
		scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
	}
	if (scale > 1 && loggingEnabled) {
		L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
	}

	Options decodingOptions = decodingInfo.getDecodingOptions();
	decodingOptions.inSampleSize = scale;
	return decodingOptions;
}
 
Example 10
Source Project: candybar   Source File: BaseImageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
                                                   int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    // Scale to exact size if need
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
        float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
                .getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1f) != 0) {
            m.setScale(scale, scale);

            if (loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
            }
        }
    }
    // Flip bitmap if need
    if (flipHorizontal) {
        m.postScale(-1, 1);

        if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
    }
    // Rotate bitmap if need
    if (rotation != 0) {
        m.postRotate(rotation);

        if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
    }

    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
            .getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}
 
Example 11
Source Project: candybar   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetImageSizeScaleTo_useImageActualSize() throws Exception {
    // We layout the view to give it a width and height
    mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY));
    mView.layout(0, 0, 200, 200);

    ImageSize expected = new ImageSize(200, 200);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590));
    Assertions.assertThat(result).isNotNull();
    Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth());
    Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight());
}
 
Example 12
Source Project: candybar   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never
 * shrunk to the first image size. In this case it falls back to the config size
 *
 * @throws Exception
 */
@Test
public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception {
    //Set it to wrap content so that it will fall back to
    mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY));
    // We layout the view to give it a width and height
    mView.layout(0, 0, 200, 200);

    ImageSize expected = new ImageSize(500, 500);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
    Assertions.assertThat(result).isNotNull().isEqualToComparingFieldByField(expected);
}
 
Example 13
Source Project: candybar   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetImageSizeScaleTo_useImageLayoutParams() throws Exception {
    // Set a defined width
    mView.setLayoutParams(new FrameLayout.LayoutParams(300, 300));

    ImageSize expected = new ImageSize(300, 300);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
    Assertions.assertThat(result).isNotNull().isEqualToComparingFieldByField(expected);
}
 
Example 14
Source Project: candybar   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testComputeImageSampleSize_fitInside() throws Exception {
    final ViewScaleType scaleType = ViewScaleType.FIT_INSIDE;
    int result;

    ImageSize srcSize = new ImageSize(300, 100);
    ImageSize targetSize = new ImageSize(30, 10);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(10);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(8);

    srcSize = new ImageSize(300, 100);
    targetSize = new ImageSize(200, 200);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(1);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(1);

    srcSize = new ImageSize(300, 100);
    targetSize = new ImageSize(55, 40);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(5);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(4);

    srcSize = new ImageSize(300, 100);
    targetSize = new ImageSize(30, 40);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(10);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(8);

    srcSize = new ImageSize(5000, 70);
    targetSize = new ImageSize(2000, 30);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(3);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(4);
}
 
Example 15
Source Project: candybar   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testComputeImageSampleSize_centerCrop() throws Exception {
    final ViewScaleType scaleType = ViewScaleType.CROP;
    int result;

    ImageSize srcSize = new ImageSize(300, 100);
    ImageSize targetSize = new ImageSize(30, 10);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(10);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(8);

    srcSize = new ImageSize(300, 100);
    targetSize = new ImageSize(200, 200);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(1);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(1);

    srcSize = new ImageSize(300, 100);
    targetSize = new ImageSize(55, 40);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(2);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(2);

    srcSize = new ImageSize(300, 100);
    targetSize = new ImageSize(30, 30);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(3);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(2);

    srcSize = new ImageSize(5000, 70);
    targetSize = new ImageSize(300, 30);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
    Assertions.assertThat(result).isEqualTo(3);
    result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
    Assertions.assertThat(result).isEqualTo(4);
}
 
Example 16
Source Project: letv   Source File: BaseImageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo, int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        float scale = ImageSizeUtils.computeImageScale(new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation), decodingInfo.getTargetSize(), decodingInfo.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1.0f) != 0) {
            m.setScale(scale, scale);
            if (this.loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), Float.valueOf(scale), decodingInfo.getImageKey());
            }
        }
    }
    if (flipHorizontal) {
        m.postScale(-1.0f, 1.0f);
        if (this.loggingEnabled) {
            L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
        }
    }
    if (rotation != 0) {
        m.postRotate((float) rotation);
        if (this.loggingEnabled) {
            L.d(LOG_ROTATE_IMAGE, Integer.valueOf(rotation), decodingInfo.getImageKey());
        }
    }
    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}
 
Example 17
Source Project: talk-android   Source File: DiskDecoder.java    License: MIT License 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
                                                   int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    // Scale to exact size if need
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
        float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
                .getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1f) != 0) {
            m.setScale(scale, scale);

            if (loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
            }
        }
    }
    // Flip bitmap if need
    if (flipHorizontal) {
        m.postScale(-1, 1);

        if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
    }
    // Rotate bitmap if need
    if (rotation != 0) {
        m.postRotate(rotation);

        if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
    }

    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
            .getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}
 
Example 18
Source Project: mobile-manager-tool   Source File: BaseImageDecoder.java    License: MIT License 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
		int rotation, boolean flipHorizontal) {
	Matrix m = new Matrix();
	// Scale to exact size if need
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
		ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
		float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
				.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
		if (Float.compare(scale, 1f) != 0) {
			m.setScale(scale, scale);

			if (loggingEnabled) {
				L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
			}
		}
	}
	// Flip bitmap if need
	if (flipHorizontal) {
		m.postScale(-1, 1);

		if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
	}
	// Rotate bitmap if need
	if (rotation != 0) {
		m.postRotate(rotation);

		if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
	}

	Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
			.getHeight(), m, true);
	if (finalBitmap != subsampledBitmap) {
		subsampledBitmap.recycle();
	}
	return finalBitmap;
}
 
Example 19
Source Project: BigApp_WordPress_Android   Source File: BaseImageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
                                                   int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    // Scale to exact size if need
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
        float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
                .getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1f) != 0) {
            m.setScale(scale, scale);

            if (loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
            }
        }
    }
    // Flip bitmap if need
    if (flipHorizontal) {
        m.postScale(-1, 1);

        if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
    }
    // Rotate bitmap if need
    if (rotation != 0) {
        m.postRotate(rotation);

        if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
    }

    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
            .getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}
 
Example 20
Source Project: WliveTV   Source File: BaseImageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
		int rotation, boolean flipHorizontal) {
	Matrix m = new Matrix();
	// Scale to exact size if need
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
		ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
		float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
				.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
		if (Float.compare(scale, 1f) != 0) {
			m.setScale(scale, scale);

			if (loggingEnabled) {
				L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
			}
		}
	}
	// Flip bitmap if need
	if (flipHorizontal) {
		m.postScale(-1, 1);

		if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
	}
	// Rotate bitmap if need
	if (rotation != 0) {
		m.postRotate(rotation);

		if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
	}

	Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
			.getHeight(), m, true);
	if (finalBitmap != subsampledBitmap) {
		subsampledBitmap.recycle();
	}
	return finalBitmap;
}
 
Example 21
Source Project: MiBandDecompiled   Source File: BaseImageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
protected android.graphics.BitmapFactory.Options prepareDecodingOptions(ImageSize imagesize, ImageDecodingInfo imagedecodinginfo)
{
    ImageScaleType imagescaletype = imagedecodinginfo.getImageScaleType();
    int i;
    android.graphics.BitmapFactory.Options options;
    if (imagescaletype == ImageScaleType.NONE)
    {
        i = ImageSizeUtils.computeMinImageSampleSize(imagesize);
    } else
    {
        ImageSize imagesize1 = imagedecodinginfo.getTargetSize();
        boolean flag;
        if (imagescaletype == ImageScaleType.IN_SAMPLE_POWER_OF_2)
        {
            flag = true;
        } else
        {
            flag = false;
        }
        i = ImageSizeUtils.computeImageSampleSize(imagesize, imagesize1, imagedecodinginfo.getViewScaleType(), flag);
    }
    if (i > 1 && loggingEnabled)
    {
        Object aobj[] = new Object[4];
        aobj[0] = imagesize;
        aobj[1] = imagesize.scaleDown(i);
        aobj[2] = Integer.valueOf(i);
        aobj[3] = imagedecodinginfo.getImageKey();
        L.d("Subsample original image (%1$s) to %2$s (scale = %3$d) [%4$s]", aobj);
    }
    options = imagedecodinginfo.getDecodingOptions();
    options.inSampleSize = i;
    return options;
}
 
Example 22
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
		int rotation, boolean flipHorizontal) {
	Matrix m = new Matrix();
	// Scale to exact size if need
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
		ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
		float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
				.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
		if (Float.compare(scale, 1f) != 0) {
			m.setScale(scale, scale);

			if (loggingEnabled) {
				L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
			}
		}
	}
	// Flip bitmap if need
	if (flipHorizontal) {
		m.postScale(-1, 1);

		if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
	}
	// Rotate bitmap if need
	if (rotation != 0) {
		m.postRotate(rotation);

		if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
	}

	Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
			.getHeight(), m, true);
	if (finalBitmap != subsampledBitmap) {
		subsampledBitmap.recycle();
	}
	return finalBitmap;
}
 
Example 23
@Test
public void testGetImageSizeScaleTo_useImageActualSize() throws Exception {
	// We layout the view to give it a width and height
	mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY));
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(200, 200);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590));
	Assertions.assertThat(result).isNotNull();
	Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth());
	Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight());
}
 
Example 24
/**
 * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never
 * shrunk to the first image size. In this case it falls back to the config size
 * 
 * @throws Exception
 */
@Test
public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception {
	//Set it to wrap content so that it will fall back to
	mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
	mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY));
	// We layout the view to give it a width and height
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(500, 500);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 25
@Test
public void testGetImageSizeScaleTo_useImageLayoutParams() throws Exception {
	// Set a defined width
	mView.setLayoutParams(new FrameLayout.LayoutParams(300, 300));

	ImageSize expected = new ImageSize(300, 300);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 26
@Test
public void testComputeImageSampleSize_fitInside() throws Exception {
	final ViewScaleType scaleType = ViewScaleType.FIT_INSIDE;
	int result;

	ImageSize srcSize = new ImageSize(300, 100);
	ImageSize targetSize = new ImageSize(30, 10);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(10);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(8);

	srcSize = new ImageSize(300, 100);
	targetSize = new ImageSize(200, 200);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(1);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(1);

	srcSize = new ImageSize(300, 100);
	targetSize = new ImageSize(55, 40);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(5);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(4);

	srcSize = new ImageSize(300, 100);
	targetSize = new ImageSize(30, 40);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(10);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(8);

	srcSize = new ImageSize(5000, 70);
	targetSize = new ImageSize(2000, 30);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(3);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(4);
}
 
Example 27
@Test
public void testComputeImageSampleSize_centerCrop() throws Exception {
	final ViewScaleType scaleType = ViewScaleType.CROP;
	int result;

	ImageSize srcSize = new ImageSize(300, 100);
	ImageSize targetSize = new ImageSize(30, 10);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(10);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(8);

	srcSize = new ImageSize(300, 100);
	targetSize = new ImageSize(200, 200);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(1);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(1);

	srcSize = new ImageSize(300, 100);
	targetSize = new ImageSize(55, 40);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(2);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(2);

	srcSize = new ImageSize(300, 100);
	targetSize = new ImageSize(30, 30);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(3);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(2);

	srcSize = new ImageSize(5000, 70);
	targetSize = new ImageSize(300, 30);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false);
	Assertions.assertThat(result).isEqualTo(3);
	result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true);
	Assertions.assertThat(result).isEqualTo(4);
}
 
Example 28
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
		int rotation, boolean flipHorizontal) {
	Matrix m = new Matrix();
	// Scale to exact size if need
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
		ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
		float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
				.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
		if (Float.compare(scale, 1f) != 0) {
			m.setScale(scale, scale);

			if (loggingEnabled) {
				L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
			}
		}
	}
	// Flip bitmap if need
	if (flipHorizontal) {
		m.postScale(-1, 1);

		if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
	}
	// Rotate bitmap if need
	if (rotation != 0) {
		m.postRotate(rotation);

		if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
	}

	Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
			.getHeight(), m, true);
	if (finalBitmap != subsampledBitmap) {
		subsampledBitmap.recycle();
	}
	return finalBitmap;
}
 
Example 29
Source Project: android-open-project-demo   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetImageSizeScaleTo_useImageActualSize() throws Exception {
	// We layout the view to give it a width and height
	mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY));
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(200, 200);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590));
	Assertions.assertThat(result).isNotNull();
	Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth());
	Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight());
}
 
Example 30
Source Project: android-open-project-demo   Source File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never
 * shrunk to the first image size. In this case it falls back to the config size
 * 
 * @throws Exception
 */
@Test
public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception {
	//Set it to wrap content so that it will fall back to
	mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
	mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY));
	// We layout the view to give it a width and height
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(500, 500);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}