I have been googling around a bit and can’t seem to find an solution. Here is my problem. I need to resize an UIImage to a specific size-namely a size so that the width and height are both powers of two. My images are coming from the camera, so the dimensions are not powers of two. I need to keep the entire image, while maintain the correct aspect-ie aspect fit mode. I know how to resize a UIImage, but I can’t figure out how to resize the image and add whitespace on the top and bottom appropriately to keep the proper overall image size, while retaining the correct aspect. Does anyone have insight on this?
BTW, here is my current resizing code(just resizes)
- (UIImage *) resizeImage:(UIImage *)initialImage
{
CGSize newSize = CGSizeMake(256, 256);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[initialImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
and I tried using this blog, but it does give me the proper image size when I specify UIViewContentModeScaleAspectFit for the content mode.
a eazy way to do that is
put your image into a UIImageView, set the size you want with the whitespace and white backgournd color, then set the UIViewContentModeScaleAspectFit mode
then turn it to a UIImage
you got it