iPhone Development

Just another iPhone Blog

Image Size With Aspect Ratio

A Snippet to calculate an Image Size to fit within a given rectangle with its Aspect Ratio maintained

ImageSize NewSizeForImageOfSize(ImageSize srcImageSize, ImageSize destSize)
{

ImageSize newSize;

if( srcImageSize.width > srcImageSize.height)
{
newSize.width=destSize.width;     newSize.height= srcImageSize.height * (destSize.width/srcImageSize.width)
}
else
{
newSize.height=destSize.height;     newSize.width= srcImageSize.width * (destSize.height/srcImageSize.height)
}

return newSize;
}

 


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: