Difference between CGAffineTransform on CIImage and UIImageView

1.1k Views Asked by At

I have been playing around with CGAffineTransform and noticed that transforming an image from the UIImageView has a different effect then transforming it directly through the CIImage. Here is the code:

let totalTransformationAndRotation = CGAffineTransform(rotationAngle: x)
// How I transform using the imageview
self.keyImage.transform = totalTransformationAndRotation
// How I transform using the image
var coreImage:CIImage? = myImage!.ciImage
if coreImage == nil {
   coreImage = CIImage(cgImage: myImage!.cgImage!)
}
coreImage = coreImage?.transformed(by: totalTransformationAndRotation)   

When used separately these two transformations come out totally differently. I understand that the unit is different for the CIImage's transformation's dx and dy and UIImageView's transformation's dx and dy, but even rotations have a different result. It appears to me that when rotated in the CIImage. The rotation is centered around the bottom left, while in the UIImageView it is centered around the center of the image.

Is it possible to rotate, scale and translate a UIImage/CIImage and have the same effect as if you applied the same transformations on a UIImageView?

Edit: I am trying to transform a UIImage by rotating, scaling, and translating. I have gotten the desired effect by applying a transforming on the UIImageView's transform property but realized that I need to do the transformation directly in the image.

0

There are 0 best solutions below