diff --git a/app/src/main/java/com/beemdevelopment/aegis/helpers/BitmapHelper.java b/app/src/main/java/com/beemdevelopment/aegis/helpers/BitmapHelper.java new file mode 100644 index 00000000..a97fb6a4 --- /dev/null +++ b/app/src/main/java/com/beemdevelopment/aegis/helpers/BitmapHelper.java @@ -0,0 +1,31 @@ +package com.beemdevelopment.aegis.helpers; + +import android.graphics.Bitmap; + +public class BitmapHelper { + private BitmapHelper() { + + } + + /** + * Scales the given Bitmap to the given maximum width/height, while keeping the aspect ratio intact. + */ + public static Bitmap resize(Bitmap bitmap, int maxWidth, int maxHeight) { + if (maxHeight <= 0 || maxWidth <= 0) { + return bitmap; + } + + float maxRatio = (float) maxWidth / maxHeight; + float ratio = (float) bitmap.getWidth() / bitmap.getHeight(); + + int width = maxWidth; + int height = maxHeight; + if (maxRatio > 1) { + width = (int) ((float) maxHeight * ratio); + } else { + height = (int) ((float) maxWidth / ratio); + } + + return Bitmap.createScaledBitmap(bitmap, width, height, true); + } +} diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java index be21dbb4..e035ab99 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java @@ -29,6 +29,7 @@ import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.R; import com.beemdevelopment.aegis.SortCategory; import com.beemdevelopment.aegis.ViewMode; +import com.beemdevelopment.aegis.helpers.BitmapHelper; import com.beemdevelopment.aegis.helpers.FabScrollHelper; import com.beemdevelopment.aegis.helpers.PermissionHelper; import com.beemdevelopment.aegis.otp.GoogleAuthInfo; @@ -310,6 +311,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene try (InputStream inputStream = getContentResolver().openInputStream(inputFile)) { bitmap = BitmapFactory.decodeStream(inputStream, null, bmOptions); + bitmap = BitmapHelper.resize(bitmap, 640, 480); } int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];