Using CoreImage to filter an image results in image rotation

后端 未结 2 1302
鱼传尺愫
鱼传尺愫 2020-12-09 21:44

Thanks for reading.

I\'m trying to use CoreImage in iOS 5 to alter the appearance of an image. The problem is that the existing image appears to lose its orientation

相关标签:
2条回答
  • 2020-12-09 21:58

    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.

    0 讨论(0)
  • 2020-12-09 22:18

    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.

    0 讨论(0)
提交回复
热议问题