On Wed, Jun 24, 2009 at 2:37 PM, Gavin Aiken <gavin.ai...@imperial.ac.uk>wrote:

> Hey all!
>
> This has been frustrating me for a while, all I want is to scale an image
> to dimensions that I define whilst keeping an aspect ratio. So for example,
> image comes in at 500 * 500, I want to scale to 320 * 480 so I need 320 *
> 320 so as not to distort the image.
>
> This must be a simple 3 lines of code using a matrix? I just can't do it,
> it's lame, i'm very tired and it turns out I suck at programming. One of
> those days! :)
>
> Any help greatly appreciated, what you have to work with is this;


It might help if you told us what "newWidth" and "width" are, and what goes
wrong when you run the code.


>         float scaleWidth = ((float) newWidth) / width;
>         float scaleHeight = ((float) newHeight) / height;
>
>         scale = larger of the two scales;
>
>         // createa matrix for the manipulation
>         Matrix matrix = new Matrix();
>         // resize the bit map
>         matrix.postScale(scale, scale);
>
>         // recreate the new Bitmap
>         Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
>                           width, height, matrix, true);
>
>
> Gav
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to