以编程方式在iphone中将UIImage比率更改为fb封面
Posted
技术标签:
【中文标题】以编程方式在iphone中将UIImage比率更改为fb封面【英文标题】:Change UIImage ratio to fb cover in iphone Programmatically 【发布时间】:2012-12-02 20:23:46 【问题描述】:我正在从图像选择器中选择一个图像,然后我想将该图像的比例更改为 facebook 封面。我有一张图像,假设它的分辨率为 640 宽和 480 高,我想将其更改为 facebook 封面(851 像素宽和 315 像素高)我将如何在 iphone 中以编程方式执行此操作 查看此link 了解封面图片详情 谢谢。
【问题讨论】:
【参考方案1】: 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。
【讨论】:
我将在 contentMode 中传递什么? UIViewContentMode 指定视图在大小变化时如何调整其内容。 typedef enum UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFit, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, 苹果文档在这里:developer.apple.com/library/ios/#documentation/UIKit/Reference/…以上是关于以编程方式在iphone中将UIImage比率更改为fb封面的主要内容,如果未能解决你的问题,请参考以下文章
如何在 iPhone 上以编程方式在 Swift 中将 UIViewController 呈现为弹出框