CGAffineTransform Reset

If you are trying to reset the transformation, so that the image appears as it did originally, you can simply set the transform back to the identity.

self.imageView.transform = CGAffineTransformIdentity

If you want to apply arbitrary transformations to the transformed image, the easiest thing to do would be to use the CGAffineTransform methods that take in an existing transformation. Just send in the existing transformation. For example:

CGAffineTransform scale = CGAffineTransformMakeScale(zoom, 1);
self.imageView.transform = CGAffineTransformConcat(self.imageView.transform, scale);

If you REALLY need the image as it appears without any transformation at all, you’ll have to draw it back into another image. That’s not that hard either, but I don’t recommend it as your first solution. This code works in the context of a UIView category for an arbitrary view, including a UIImageView:

- (UIImage *) capture {
    CGRect screenRect = self.frame;
    CGFloat scale = [[UIScreen mainScreen] scale];
    UIGraphicsBeginImageContextWithOptions(screenRect.size, YES, scale);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextFillRect(ctx, screenRect);

    [self.layer renderInContext: ctx];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;
}

Leave a Comment

tech