我正在从图像选择器中选择一个图像,然后我想更改该图像的比例作为facebook封面。我有一个图像,假设它的分辨率为640宽度和480高度,我想将其更改为facebook封面(851像素宽和315像素高),我将如何在iPhone中以编程方式进行操作
检查此link以获取封面图片详细信息
谢谢。

最佳答案

 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];

}

并通过此链接获取更多详细信息Resizing Uiimage in right way

关于iphone - 以编程方式将iphone的UIImage比率更改为fb封面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13673468/

10-14 21:38