Fix exif dimension edge case and handle invalid dimens better in ThumbnailView.
This commit is contained in:
parent
9d14bcb808
commit
c7ef0c06f8
2 changed files with 9 additions and 8 deletions
|
@ -113,10 +113,15 @@ public class ThumbnailView extends FrameLayout {
|
||||||
|
|
||||||
@SuppressWarnings("SuspiciousNameCombination")
|
@SuppressWarnings("SuspiciousNameCombination")
|
||||||
private void fillTargetDimensions(int[] targetDimens, int[] dimens, int[] bounds) {
|
private void fillTargetDimensions(int[] targetDimens, int[] dimens, int[] bounds) {
|
||||||
int dimensFilledCount = getNonZeroCount(dimens);
|
int dimensFilledCount = getNonZeroCount(dimens);
|
||||||
int boundsFilledCount = getNonZeroCount(bounds);
|
int boundsFilledCount = getNonZeroCount(bounds);
|
||||||
|
boolean dimensAreInvalid = dimensFilledCount > 0 && dimensFilledCount < dimens.length;
|
||||||
|
|
||||||
if (dimensFilledCount == 0 || boundsFilledCount == 0) {
|
if (dimensAreInvalid) {
|
||||||
|
Log.w(TAG, String.format(Locale.ENGLISH, "Width or height has been specified, but not both. Dimens: %d x %d", dimens[WIDTH], dimens[HEIGHT]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimensAreInvalid || dimensFilledCount == 0 || boundsFilledCount == 0) {
|
||||||
targetDimens[WIDTH] = 0;
|
targetDimens[WIDTH] = 0;
|
||||||
targetDimens[HEIGHT] = 0;
|
targetDimens[HEIGHT] = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -130,10 +135,6 @@ public class ThumbnailView extends FrameLayout {
|
||||||
int minHeight = bounds[MIN_HEIGHT];
|
int minHeight = bounds[MIN_HEIGHT];
|
||||||
int maxHeight = bounds[MAX_HEIGHT];
|
int maxHeight = bounds[MAX_HEIGHT];
|
||||||
|
|
||||||
if (dimensFilledCount > 0 && dimensFilledCount < dimens.length) {
|
|
||||||
throw new IllegalStateException(String.format(Locale.ENGLISH, "Width or height has been specified, but not both. Dimens: %f x %f",
|
|
||||||
naturalWidth, naturalHeight));
|
|
||||||
}
|
|
||||||
if (boundsFilledCount > 0 && boundsFilledCount < bounds.length) {
|
if (boundsFilledCount > 0 && boundsFilledCount < bounds.length) {
|
||||||
throw new IllegalStateException(String.format(Locale.ENGLISH, "One or more min/max dimensions have been specified, but not all. Bounds: [%d, %d, %d, %d]",
|
throw new IllegalStateException(String.format(Locale.ENGLISH, "One or more min/max dimensions have been specified, but not all. Bounds: [%d, %d, %d, %d]",
|
||||||
minWidth, maxWidth, minHeight, maxHeight));
|
minWidth, maxWidth, minHeight, maxHeight));
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class BitmapUtil {
|
||||||
ExifInterface exif = new ExifInterface(inputStream);
|
ExifInterface exif = new ExifInterface(inputStream);
|
||||||
int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
|
int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
|
||||||
int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
|
int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
|
||||||
if (width == 0 && height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue