水平翻转CIImage



我正试图用水平翻转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)];

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

在对象C:中

image = [image imageByApplyingCGOrientation: kCGImagePropertyOrientationUpMirrored];

Swift:

image = image.oriented(.upMirrored)

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

如果您想要的是将其定向为可以在UIImage中使用它,那么您需要在两个轴上翻转它。

image = image.oriented(.downMirrored)

Alex几乎做到了,但你也需要调整翻译:

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

这对我有效:

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

这将允许您在水平或垂直方向上翻转UIImage(或CIImage):

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];

相关内容

  • 没有找到相关文章

最新更新