Tuesday, August 31, 2010

Working With Bitmap Images in Android

  Scaling an Bitmap Image : 
Let suppose you have an image named bar.png in the folder drawable  of your project with size 200 * 200 px. And you wanted to scale it to some size let suppose 400 * 400 px.


Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.bar);
bmp = Bitmap.createScaledBitmap(bmp, 400,400,  true);

Now your image is scaled to 400 * 400 px.

 Rotating an Bitmap Image :  

                Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.bar);
                Matrix mtx = new Matrix();
mtx.postRotate(180);   // rotating 180 degrees clockwise
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth() ,bmp.getHeight() , mtx, true);  // creating the bitmap image with new angle.

Now , bmp has original image, rotatedBMP has image with 180 degrees rotated.




2 comments:

  1. Ι all the tіmе uѕed tο study piеce of writing in news ρapers but noω as I
    am a user of web therefore from nοω I am uѕіng net foг content,
    thanks tο wеb.

    Look intо my page: best cheap stairlift online

    ReplyDelete
  2. Informatіve aгtісlе, exaсtly what I wаntеd
    to find.

    My website: Hublifte günstig

    ReplyDelete

Android Developers Blog

Ram's shared items

Amazon Product Ads