Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74d9576b authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Recycle the original bitmap after scaling down

This will free the memory used by the original bitmap

Bug: 290862169
Bug: 304567418
Test: Manual. Install the APK attached in b/290862169#comment18
Change-Id: I94f5a9a4313c13375062fdade0e672d51eb5dc55
parent 2fc482f6
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ public class PackageUtil {

        private Bitmap getBitmapFromDrawable(Drawable drawable) {
            // Create an empty bitmap with the dimensions of our drawable
            Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            // Associate it with a canvas. This canvas will draw the icon on the bitmap
@@ -183,7 +183,11 @@ public class PackageUtil {

            // Scale it down if the icon is too large
            if ((bmp.getWidth() > iconSize * 2) || (bmp.getHeight() > iconSize * 2)) {
                bmp = Bitmap.createScaledBitmap(bmp, iconSize, iconSize, true);
                Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmp, iconSize, iconSize, true);
                if (scaledBitmap != bmp) {
                    bmp.recycle();
                }
                return scaledBitmap;
            }
            return bmp;
        }