从CIImage转换后的侧面UIImage [英] UIImage sideway after converting it from CIImage

查看:89
本文介绍了从CIImage转换后的侧面UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对UIImage应用过滤器,但转换后,它显示为横向。下面是我的代码。

I'm applying filter on UIImage but after conversion, it appear as sideway. 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];

它可以成功地在newImage和尺寸中渲染,但是图像是横向的。上面的代码中是否有任何地方会引起方向变化?

It renders successfully in newImage, and dimensions, but the image is side way. Is there any place in above code that cause orientation change ?

推荐答案

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

Scale the image to proper orientation before applying 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];

这篇关于从CIImage转换后的侧面UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆