[英]How to rotate UIImage to post a photo on a website/Facebook with proper orientation?
if I take a photo with the iPhone camera, I see that photo is 90 degree rotated. 如果我使用iPhone相机拍摄照片,则会看到该照片旋转了90度。 For instance if device orientation is UIDeviceOrientationPortrait the UIImage orientation is UIImageOrientationRight. 例如,如果设备方向为UIDeviceOrientationPortrait,则UIImage方向为UIImageOrientationRight。 How can I rotate the UIIMage so that if I post it on a website or Facebook, the photo is correctly orientated? 如何旋转UIIMage,以便将其发布在网站或Facebook上时,照片的方向是否正确?
I'm using this function in a UIImage category: 我在UIImage类别中使用此功能:
- (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];
}
then just call: 然后只需致电:
UIImage *myCameraRollImage = ..//image received from camera roll
UIImage *mFixedRotationImage = [myCameraRollImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(width, height) interpolationQuality:kCGInterpolationHigh];
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.