BitmapUtil.java
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.gimi.common.cinema.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
public class BitmapUtil {
public BitmapUtil() {
}
public static Bitmap getBitmapThumbnail(String path, int width, int height) {
Bitmap bitmap;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, opts);
opts.inSampleSize = Math.max((int) (opts.outHeight / (float) height), (int) (opts.outWidth / (float) width));
opts.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(path, opts);
return bitmap;
}
public static Bitmap getBitmapThumbnail(Bitmap bmp, int width, int height) {
Bitmap bitmap = null;
if (bmp != null) {
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
if (width != 0 && height != 0) {
Matrix matrix = new Matrix();
float scaleWidth = ((float) width / bmpWidth);
float scaleHeight = ((float) height / bmpHeight);
matrix.postScale(scaleWidth, scaleHeight);
bitmap = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
} else {
bitmap = bmp;
}
}
return bitmap;
}
}