Show video thumbnail on the lock screen
This commit is contained in:
parent
c56fb8cec2
commit
f44883e79f
3 changed files with 125 additions and 21 deletions
42
app/src/main/java/org/schabi/newpipe/util/BitmapUtils.java
Normal file
42
app/src/main/java/org/schabi/newpipe/util/BitmapUtils.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class BitmapUtils {
|
||||
|
||||
@Nullable
|
||||
public static Bitmap centerCrop(Bitmap inputBitmap, int newWidth, int newHeight) {
|
||||
if (inputBitmap == null || inputBitmap.isRecycled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
float sourceWidth = inputBitmap.getWidth();
|
||||
float sourceHeight = inputBitmap.getHeight();
|
||||
|
||||
float xScale = newWidth / sourceWidth;
|
||||
float yScale = newHeight / sourceHeight;
|
||||
|
||||
float newXScale;
|
||||
float newYScale;
|
||||
|
||||
if (yScale > xScale) {
|
||||
newXScale = (1.0f / yScale) * xScale;
|
||||
newYScale = 1.0f;
|
||||
} else {
|
||||
newXScale = 1.0f;
|
||||
newYScale = (1.0f / xScale) * yScale;
|
||||
}
|
||||
|
||||
float scaledWidth = newXScale * sourceWidth;
|
||||
float scaledHeight = newYScale * sourceHeight;
|
||||
|
||||
int left = (int) ((sourceWidth - scaledWidth) / 2);
|
||||
int top = (int) ((sourceHeight - scaledHeight) / 2);
|
||||
int width = (int) scaledWidth;
|
||||
int height = (int) scaledHeight;
|
||||
|
||||
return Bitmap.createBitmap(inputBitmap, left, top, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue