从CIImage转换它后UIImage横向

我在UIImage应用filter,但转换后,它显示为侧面。 以下是我的代码。

CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess]; CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectChrome" keysAndValues:kCIInputImageKey, ciImage, nil]; [filter setDefaults]; CIContext *context = [CIContext contextWithOptions:nil]; CIImage *outputImage = [filter outputImage]; CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]]; UIImage *newImage = [[UIImage alloc]initWithCIImage:outputImage]; 

它在newImage和尺寸中成功呈现,但图像是侧面的。 上面的代码中有没有导致方向改变的地方?

在应用filter之前将图像缩放到正确的方向。

请按照以下链接: https : //stackoverflow.com/q/538064/871102

代替:

 CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess]; 

写:

 UIImage *properOrientedImage = [self scaleAndRotateImage:self.imgToProcess]; CIImage *ciImage = [[CIImage alloc] initWithImage:properOrientedImage.CGImage]; 

是的,你可以考虑设置图像方向,以确保使用方法初始化UIImage

 - (id)initWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation 

你有几个图像方向:

 typedef enum { UIImageOrientationUp, UIImageOrientationDown, // 180 deg rotation UIImageOrientationLeft, // 90 deg CW UIImageOrientationRight, // 90 deg CCW UIImageOrientationUpMirrored, // as above but image mirrored along // other axis. horizontal flip UIImageOrientationDownMirrored, // horizontal flip UIImageOrientationLeftMirrored, // vertical flip UIImageOrientationRightMirrored, // vertical flip } UIImageOrientation; 

Up是默认的 – 所以试着旋转它。