diff --git a/app/src/main/java/om/sstvencoder/CropView.java b/app/src/main/java/om/sstvencoder/CropView.java index 6a9e364..1e9c4b8 100644 --- a/app/src/main/java/om/sstvencoder/CropView.java +++ b/app/src/main/java/om/sstvencoder/CropView.java @@ -180,7 +180,7 @@ public class CropView extends ImageView { invalidate(); } - public void setBitmap(@NonNull InputStream stream) throws IOException { + public void setBitmap(@NonNull InputStream stream) throws IOException, IllegalArgumentException { mImageOK = false; mOrientation = 0; recycle(); @@ -188,7 +188,7 @@ public class CropView extends ImageView { invalidate(); } - private void loadImage(InputStream stream) throws IOException { + private void loadImage(InputStream stream) throws IOException, IllegalArgumentException { // app6 + exif int bufferBytes = 1048576; if (!stream.markSupported()) @@ -212,7 +212,11 @@ public class CropView extends ImageView { if (mCacheBitmap == null && mRegionDecoder == null) { String size = options.outWidth + "x" + options.outHeight; - throw new IOException("Stream could not be decoded. Image size: " + size); + String message = "Stream could not be decoded. Image size: " + size; + if (mImageWidth <= 0 || mImageHeight <= 0) + throw new IllegalArgumentException(message); + else + throw new IOException(message); } mImageOK = true; diff --git a/app/src/main/java/om/sstvencoder/MainActivity.java b/app/src/main/java/om/sstvencoder/MainActivity.java index 1b3bc23..8f414ac 100644 --- a/app/src/main/java/om/sstvencoder/MainActivity.java +++ b/app/src/main/java/om/sstvencoder/MainActivity.java @@ -130,6 +130,9 @@ public class MainActivity extends AppCompatActivity { private boolean loadImage(InputStream stream, ContentResolver resolver, Uri uri) { try { mCropView.setBitmap(stream); + } catch (IllegalArgumentException ex) { + Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show(); + return false; } catch (Exception ex) { String s = Utility.createMessage(ex) + "\n\n" + uri; showErrorMessage(getString(R.string.load_img_err_title), ex.getMessage(), s);