简体   繁体   中英

Change UIImage ratio to fb cover in iphone Programmatically

I am picking an image from image picker and then i want to change ratios for that image as facebook cover. i have an image let suppose its resolution ia 640 widht and 480 height and i want to change it for facebook cover(851 pixels wide and 315 pixels tall) how will i do that programmatically in iphone Check this link for cover picture details Thanks.

 Use this Method to Resize the image according to the given content mode, taking into account the image's orientation...

- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode bounds:(CGSize)bounds
                interpolationQuality:(CGInterpolationQuality)quality {

CGFloat horizontalRatio = bounds.width / self.size.width;
CGFloat verticalRatio = bounds.height / self.size.height;
CGFloat ratio;

switch (contentMode) {
    case UIViewContentModeScaleAspectFill:
        ratio = MAX(horizontalRatio, verticalRatio);
        break;

    case UIViewContentModeScaleAspectFit:
        ratio = MIN(horizontalRatio, verticalRatio);
        break;

    default:
        [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode:  %d", contentMode];
}

CGSize newSize = CGSizeMake(self.size.width * ratio, self.size.height * ratio);

return [self resizedImage:newSize interpolationQuality:quality];

}

and go this this link for more detail, Resizing Uiimage in right way .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM