水平翻转 CIImage

Flip CIImage Horizontal

我正在尝试水平翻转我的 CIImage :

image = [image imageByApplyingTransform:CGAffineTransformMakeScale(1, -1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(0, sourceExtent.size.height)];

但我总是让图像垂直翻转

试试这个方法:

image = [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(0, sourceExtent.size.height)];

Alex 差不多搞定了,但你还需要调整一下翻译:

image = [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(sourceExtent.size.width, 0)];

这将正确地水平翻转图像并保持正确的坐标。

在 Obj-C 中:

image = [image imageByApplyingCGOrientation: kCGImagePropertyOrientationUpMirrored];

在Swift中:

image = image.oriented(.upMirrored)

https://developer.apple.com/documentation/coreimage/ciimage/2919727-oriented

如果您想要以可以在 UIImage 中使用它的方式定位它,那么您想要在两个轴上翻转它。

image = image.oriented(.downMirrored)

这对我有用:

UIImage(ciImage: ciImage.oriented(.upMirrored).oriented(.left))