Resizing and rotating an image in Android

Posted by kingrichard2005 on Stack Overflow See other posts from Stack Overflow or by kingrichard2005
Published on 2010-04-08T06:09:22Z Indexed on 2010/04/08 6:13 UTC
Read the original article Hit count: 641

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about java