Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip CIImage Horizontal

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

like image 849
YosiFZ Avatar asked Dec 03 '22 15:12

YosiFZ


2 Answers

Try this way:

image = [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(0, sourceExtent.size.height)];
like image 78
Alex Kosyakov Avatar answered Dec 29 '22 10:12

Alex Kosyakov


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)
like image 21
Luis Avatar answered Dec 29 '22 10:12

Luis