简体   繁体   English

从CIImage转换后的侧面UIImage

[英]UIImage sideway after converting it from CIImage

I'm applying filter on UIImage but after conversion, it appear as sideway. 我在UIImage上应用了过滤器,但在转换后,它显示为横向。 Below is my code. 下面是我的代码。

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

It renders successfully in newImage, and dimensions, but the image is side way. 它可以在newImage和尺寸中成功渲染,但是图像是侧面的。 Is there any place in above code that cause orientation change ? 上面的代码中是否有任何地方会引起方向变化?

Scale the image to proper orientation before applying filter. 在应用滤镜之前,将图像缩放到正确的方向。

follow this link: https://stackoverflow.com/q/538064/871102 跟随这个链接: https : //stackoverflow.com/q/538064/871102

Instead of: 代替:

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

write: 写:

UIImage *properOrientedImage = [self scaleAndRotateImage:self.imgToProcess];

CIImage *ciImage = [[CIImage alloc] initWithImage:properOrientedImage.CGImage];

Yes, you may consider setting the image orientation to be sure of one initializing the UIImage with method: 是的,您可以考虑设置图像方向,以确保可以使用方法初始化UIImage

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

And you have couple of image orientations: 您有几种图像方向:

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;

The Up is default - so try to rotate it. Up是默认设置-请尝试旋转它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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