Merge "Prevent LocalImageResolver from upscaling images" into tm-dev
This commit is contained in:
@@ -198,6 +198,11 @@ public class LocalImageResolver {
|
||||
}
|
||||
|
||||
final Size size = info.getSize();
|
||||
if (size.getWidth() <= maxWidth && size.getHeight() <= maxHeight) {
|
||||
// We don't want to upscale images needlessly.
|
||||
return;
|
||||
}
|
||||
|
||||
if (size.getWidth() > size.getHeight()) {
|
||||
if (size.getWidth() > maxWidth) {
|
||||
final int targetHeight = size.getHeight() * maxWidth / size.getWidth();
|
||||
|
||||
@@ -194,6 +194,17 @@ public class LocalImageResolverTest {
|
||||
assertThat(bd.getBitmap().getHeight()).isGreaterThan(51);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveImage_smallBitmapIcon_passedSmallerSize_dontResize() {
|
||||
Icon icon = Icon.createWithResource(mContext.getResources(), R.drawable.test32x24);
|
||||
Drawable d = LocalImageResolver.resolveImage(icon, mContext, 600, 450);
|
||||
|
||||
assertThat(d).isInstanceOf(BitmapDrawable.class);
|
||||
BitmapDrawable bd = (BitmapDrawable) d;
|
||||
assertThat(bd.getBitmap().getWidth()).isEqualTo(32);
|
||||
assertThat(bd.getBitmap().getHeight()).isEqualTo(24);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveImage_largeBitmapIcon_passedSize_resizeToDefinedSize() {
|
||||
Icon icon = Icon.createWithBitmap(
|
||||
|
||||
Reference in New Issue
Block a user