Flipping a UIImage

Flipping an image using objective-c is so easy once you know how...

//Create a normal image
UIImage* img = [UIImage imageNamed:@"myImage.png"];
//Flip it
UIImage* flippedImage = [UIImage imageWithCGImage:img.CGImage scale:1.0 orientation:  UIImageOrientationDownMirrored];

That's it! Now to have it as an method we can use more conveniently, try this:

-(UIImage *)flipImage:(UIImage *)img {
    UIImage* flippedImage = [UIImage imageWithCGImage:img.CGImage scale:1.0 orientation:  UIImageOrientationDownMirrored];
    return flippedImage;
}

Then we can send any image to it and it will return a flipped version.

Published on

Discuss!

comments powered by Disqus