Reputation: 7890
I am trying to flip my CIImage Horizontal with :
image = [image imageByApplyingTransform:CGAffineTransformMakeScale(1, -1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(0, sourceExtent.size.height)];
But i always get the image flip vertical instead
Upvotes: 6
Views: 4401
Reputation: 17882
This will allow you to flip a UIImage (or CIImage) in either horizontal or vertical directions:
UIImage *image;
BOOL mirrorX, mirrorY;
CIImage *ciimage = [CIImage imageWithCGImage:image.CGImage];
ciimage = [ciimage imageByApplyingTransform:CGAffineTransformMakeScale(mirrorX?-1:1, mirrorY?-1:1)];
ciimage = [ciimage imageByApplyingTransform:CGAffineTransformMakeTranslation(mirrorX?image.size.width:0, mirrorY?image.size.height:0)];
image = [UIImage imageWithCIImage:ciimage];
Upvotes: 0
Reputation: 2356
This what worked for me:
UIImage(ciImage: ciImage.oriented(.upMirrored).oriented(.left))
Upvotes: 1
Reputation: 301
This will properly flip the image horizontally and maintain proper coordinates.
In Obj-C:
image = [image imageByApplyingCGOrientation: kCGImagePropertyOrientationUpMirrored];
In Swift:
image = image.oriented(.upMirrored)
https://developer.apple.com/documentation/coreimage/ciimage/2919727-oriented
If what you want is to orient it in such a way that you can use it in an UIImage, then you want to flip it in both axes.
image = image.oriented(.downMirrored)
Upvotes: 7
Reputation: 443
Alex almost had it, but you need to adjust the translation as well:
image = [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(sourceExtent.size.width, 0)];
Upvotes: 2
Reputation: 2176
Try this way:
image = [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(0, sourceExtent.size.height)];
Upvotes: 10