Skip to content

Commit

Permalink
Merge pull request #14270 from nextcloud/bugfix/handle-png-software-r…
Browse files Browse the repository at this point in the history
…endering

BugFix - ThumbnailCacheManager Software rendering doesn't support hardware bitmaps
  • Loading branch information
tobiasKaminsky authored Jan 8, 2025
2 parents e330275 + 6d2a8be commit 5f752d9
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down Expand Up @@ -1260,9 +1261,11 @@ public AsyncMediaThumbnailDrawable(Resources res, Bitmap bitmap) {
}

/**
* adapted from https://stackoverflow.com/a/8113368
* adapted from <a href="https://stackoverflow.com/a/8113368">...</a>
*/
private static Bitmap handlePNG(Bitmap source, int newWidth, int newHeight) {
Bitmap softwareBitmap = source.copy(Bitmap.Config.ARGB_8888, false);

int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();

Expand All @@ -1281,8 +1284,9 @@ private static Bitmap handlePNG(Bitmap source, int newWidth, int newHeight) {
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(dest);
canvas.drawColor(MainApp.getAppContext().getResources().getColor(R.color.background_color_png));
canvas.drawBitmap(source, null, targetRect, null);
int color = ContextCompat.getColor(MainApp.getAppContext(),R.color.background_color_png);
canvas.drawColor(color);
canvas.drawBitmap(softwareBitmap, null, targetRect, null);

return dest;
}
Expand Down

0 comments on commit 5f752d9

Please sign in to comment.