Using CoreImage to filter an image results in image rotation

放肆的年华 提交于 2019-11-28 09:23:17
Xavi Gil

Have a look at this answer https://stackoverflow.com/q/538064/871102

You can solve your problem passing the image to the method of the previous answer. So instead of:

CIImage *img = [CIImage imageWithCGImage:imageView.image.CGImage];

write:

UIImage *fixedImage = [self scaleAndRotateImage:imageView.image];
CIImage *img = [CIImage imageWithCGImage:fixedImage.CGImage];

UPDATE:

There is a more elegant answer without image scaling here: iOS UIImagePickerController result image orientation after upload.

Actually, the solution to my issue turned out to be quite simple. Since the CGImage loses its orientation and scale factors, I simply needed to add

UIImageOrientation originalOrientation = imageView.image.imageOrientation;
CGFloat originalScale = imageView.image.scale;

early in the code and then used this instead of [UIImage imageWithCGImage:]

    UIImage *newPtImage = [UIImage imageWithCGImage:img2 scale:originalScale orientation:originalOrientation];

Thanks for the suggestions too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!