Resizing and rotating an image in Android
- by kingrichard2005
I'm trying to rotate and resize an image in Android. The code I have is as follows, (taken from this tutorial):
Bitmap originalSprite = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int orgHeight = a.getHeight();
int orgWidth = a.getWidth();
//Create manipulation matrix
Matrix m = new Matrix();
// resize the bit map
m.postScale(.25f, .25f);
// rotate the Bitmap by the given angle
m.postRotate(180);
//Rotated bitmap
Bitmap rotatedBitmap = Bitmap.createBitmap(originalSprite, 0, 0,
orgWidth, orgHeight, m, true);
return rotatedBitmap;
The image seems to rotate just fine, but it doesn't scale like I expect it to. I've tried different values, but the image only gets more pixelized as I reduce the scale values, but remains that same size visually; whereas the goal I'm trying to achieve is to actually shrink it visually. I'm not sure what to do at this point, any help is appreciated.