mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Merge pull request #9479 from Stypox/create-scaled-bitmap
Use smoother bitmap downscaling for thumbnails
This commit is contained in:
commit
72a250b610
@ -8,6 +8,7 @@ import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.graphics.BitmapCompat;
|
||||
import androidx.core.math.MathUtils;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
@ -91,8 +92,8 @@ public final class SeekbarPreviewThumbnailHelper {
|
||||
final float scaleFactor = (float) newWidth / srcWidth;
|
||||
final int newHeight = (int) (srcBitmap.getHeight() * scaleFactor);
|
||||
|
||||
currentSeekbarPreviewThumbnail.setImageBitmap(
|
||||
Bitmap.createScaledBitmap(srcBitmap, newWidth, newHeight, true));
|
||||
currentSeekbarPreviewThumbnail.setImageBitmap(BitmapCompat.createScaledBitmap(srcBitmap,
|
||||
newWidth, newHeight, null, true));
|
||||
} catch (final Exception ex) {
|
||||
Log.e(TAG, "Failed to resize and set seekbar preview thumbnail", ex);
|
||||
currentSeekbarPreviewThumbnail.setVisibility(View.GONE);
|
||||
|
@ -42,6 +42,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.core.graphics.BitmapCompat;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.math.MathUtils;
|
||||
import androidx.core.view.ViewCompat;
|
||||
@ -455,10 +456,11 @@ public abstract class VideoPlayerUi extends PlayerUi
|
||||
}
|
||||
|
||||
final float endScreenHeight = calculateMaxEndScreenThumbnailHeight(thumbnail);
|
||||
final Bitmap endScreenBitmap = Bitmap.createScaledBitmap(
|
||||
final Bitmap endScreenBitmap = BitmapCompat.createScaledBitmap(
|
||||
thumbnail,
|
||||
(int) (thumbnail.getWidth() / (thumbnail.getHeight() / endScreenHeight)),
|
||||
(int) endScreenHeight,
|
||||
null,
|
||||
true);
|
||||
|
||||
if (DEBUG) {
|
||||
|
@ -9,6 +9,7 @@ import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.graphics.BitmapCompat;
|
||||
|
||||
import com.squareup.picasso.Cache;
|
||||
import com.squareup.picasso.LruCache;
|
||||
@ -139,21 +140,23 @@ public final class PicassoHelper {
|
||||
.getDimension(R.dimen.player_notification_thumbnail_width),
|
||||
source.getWidth());
|
||||
|
||||
final Bitmap result = Bitmap.createScaledBitmap(
|
||||
final Bitmap result = BitmapCompat.createScaledBitmap(
|
||||
source,
|
||||
(int) notificationThumbnailWidth,
|
||||
(int) (source.getHeight()
|
||||
/ (source.getWidth() / notificationThumbnailWidth)),
|
||||
null,
|
||||
true);
|
||||
|
||||
if (result == source) {
|
||||
if (result == source || !result.isMutable()) {
|
||||
// create a new mutable bitmap to prevent strange crashes on some
|
||||
// devices (see #4638)
|
||||
final Bitmap copied = Bitmap.createScaledBitmap(
|
||||
final Bitmap copied = BitmapCompat.createScaledBitmap(
|
||||
source,
|
||||
(int) notificationThumbnailWidth - 1,
|
||||
(int) (source.getHeight() / (source.getWidth()
|
||||
/ (notificationThumbnailWidth - 1))),
|
||||
null,
|
||||
true);
|
||||
source.recycle();
|
||||
return copied;
|
||||
|
Loading…
Reference in New Issue
Block a user