初心

何期自性,本自具足

对Bitmap进行缩放

| Comments

使用以下方法对Bitmap进行缩放

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) {
         if (bitmap == null) {
             return null;
         }

         int w = bitmap.getWidth();
         int h = bitmap.getHeight();
         Matrix matrix = new Matrix();
         float scaleWidth = ((float) width / w);
         float scaleHeight = ((float) height / h);
         matrix.postScale(scaleWidth, scaleHeight);
         Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
         return newbmp;
    }

或者直接使用

1
2
3
import android.media.ThumbnailUtils;
//... ...
ThumbnailUtils.extractThumbnail(Bitmap bitmap, int width, int height)方法

Comments