mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 08:02:24 +00:00
Handle failed bitmap decoding
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
public class BitmapDecodingException extends Throwable {
|
||||
public BitmapDecodingException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class BitmapUtil {
|
||||
|
||||
public static byte[] createScaledBytes(Context context, Uri uri, int maxWidth,
|
||||
int maxHeight, int maxSize)
|
||||
throws IOException
|
||||
throws IOException, BitmapDecodingException
|
||||
{
|
||||
InputStream measure = context.getContentResolver().openInputStream(uri);
|
||||
InputStream data = context.getContentResolver().openInputStream(uri);
|
||||
@@ -44,6 +44,7 @@ public class BitmapUtil {
|
||||
|
||||
public static Bitmap createScaledBitmap(InputStream measure, InputStream data,
|
||||
int maxWidth, int maxHeight)
|
||||
throws BitmapDecodingException
|
||||
{
|
||||
BitmapFactory.Options options = getImageDimensions(measure);
|
||||
int imageWidth = options.outWidth;
|
||||
@@ -62,6 +63,10 @@ public class BitmapUtil {
|
||||
|
||||
Bitmap roughThumbnail = BitmapFactory.decodeStream(data, null, options);
|
||||
|
||||
if (roughThumbnail == null) {
|
||||
throw new BitmapDecodingException("Decoded stream was null.");
|
||||
}
|
||||
|
||||
if (imageWidth > maxWidth || imageHeight > maxHeight) {
|
||||
Log.w("BitmapUtil", "Scaling to max width and height: " + maxWidth + "," + maxHeight);
|
||||
Bitmap scaledThumbnail = Bitmap.createScaledBitmap(roughThumbnail, maxWidth, maxHeight, true);
|
||||
|
||||
Reference in New Issue
Block a user