01 |
public static Drawable
resizeImage(Bitmap bitmap, int w, int h)
{ |
02 |
03 |
//
load the origial Bitmap |
04 |
Bitmap
BitmapOrg = bitmap; |
05 |
06 |
int width
= BitmapOrg.getWidth(); |
07 |
int height
= BitmapOrg.getHeight(); |
08 |
int newWidth
= w; |
09 |
int newHeight
= h; |
10 |
11 |
//
calculate the scale |
12 |
float scaleWidth
= (( float )
newWidth) / width; |
13 |
float scaleHeight
= (( float )
newHeight) / height; |
14 |
15 |
//
create a matrix for the manipulation |
16 |
Matrix
matrix = new Matrix(); |
17 |
//
resize the Bitmap |
18 |
matrix.postScale(scaleWidth,
scaleHeight); |
19 |
//
if you want to rotate the Bitmap |
20 |
//
matrix.postRotate(45); |
21 |
22 |
//
recreate the new Bitmap |
23 |
Bitmap
resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0 , 0 ,
width, |
24 |
height,
matrix, true ); |
25 |
26 |
//
make a Drawable from Bitmap to allow to set the Bitmap |
27 |
//
to the ImageView, ImageButton or what ever |
28 |
return new BitmapDrawable(resizedBitmap); |
29 |
30 |
} |