73 lines
2.6 KiB
Java
73 lines
2.6 KiB
Java
package cn.com.magnity.magnitycx.sdk;
|
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.Point;
|
|
import android.media.ThumbnailUtils;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class BitmapUtilities {
|
|
public static Bitmap getBitmapThumbnail(String pathName, int width, int height) {
|
|
Bitmap bitmap = null;
|
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
|
opts.inJustDecodeBounds = true;
|
|
BitmapFactory.decodeFile(pathName, opts);
|
|
if (opts.outWidth > 0 && opts.outHeight > 0) {
|
|
float r = Math.max(opts.outHeight / height, opts.outWidth / width);
|
|
opts.inSampleSize = (int) (r + 0.5d);
|
|
opts.inJustDecodeBounds = false;
|
|
bitmap = BitmapFactory.decodeFile(pathName, opts);
|
|
}
|
|
if (bitmap == null) {
|
|
return ThumbnailUtils.createVideoThumbnail(pathName, 1);
|
|
}
|
|
return bitmap;
|
|
}
|
|
|
|
public static Bitmap getBitmapThumbnail(String pathName, int sampleSize) {
|
|
Bitmap bitmap = null;
|
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
|
opts.inJustDecodeBounds = true;
|
|
BitmapFactory.decodeFile(pathName, opts);
|
|
if (opts.outWidth > 0 && opts.outHeight > 0) {
|
|
opts.inSampleSize = sampleSize;
|
|
opts.inJustDecodeBounds = false;
|
|
bitmap = BitmapFactory.decodeFile(pathName, opts);
|
|
}
|
|
if (bitmap == null) {
|
|
return ThumbnailUtils.createVideoThumbnail(pathName, 1);
|
|
}
|
|
return bitmap;
|
|
}
|
|
|
|
public static Point getBitmapSize(String pathName) {
|
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
|
opts.inJustDecodeBounds = true;
|
|
BitmapFactory.decodeFile(pathName, opts);
|
|
if (opts.outWidth <= 0 || opts.outHeight <= 0) {
|
|
return null;
|
|
}
|
|
return new Point(opts.outWidth, opts.outHeight);
|
|
}
|
|
|
|
public static Bitmap getBitmapThumbnail(Bitmap bmp, int width, int height) {
|
|
Bitmap bitmap;
|
|
if (bmp == null) {
|
|
return null;
|
|
}
|
|
int bmpWidth = bmp.getWidth();
|
|
int bmpHeight = bmp.getHeight();
|
|
if (width > 0 && height > 0) {
|
|
Matrix matrix = new Matrix();
|
|
float scaleWidth = width / bmpWidth;
|
|
float scaleHeight = height / bmpHeight;
|
|
matrix.postScale(scaleWidth, scaleHeight);
|
|
bitmap = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
|
|
} else {
|
|
bitmap = bmp;
|
|
}
|
|
return bitmap;
|
|
}
|
|
}
|