Skip to content

Instantly share code, notes, and snippets.

@codelance
Created February 8, 2013 05:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codelance/4736945 to your computer and use it in GitHub Desktop.
Save codelance/4736945 to your computer and use it in GitHub Desktop.
I felt this deserved a little more recognition so I am posting it on a public code medium. I was looking for a way to flip a NSImage vertically an horizontally. Thanks buddy @ http://itscoderslife.wordpress.com/2011/03/02/rotate-scale-flip-nsimageview/
- (void)flipImageVertically {
NSAffineTransform *flipper = [NSAffineTransform transform];
NSSize dimensions = self.size;
[self lockFocus];
[flipper scaleXBy:1.0 yBy:-1.0];
[flipper set];
[self drawAtPoint:NSMakePoint(0,-dimensions.height)
fromRect:NSMakeRect(0,0, dimensions.width, dimensions.height)
operation:NSCompositeCopy fraction:1.0];
[self unlockFocus];
}
- (void)flipImageHorizontally {
NSAffineTransform *flipper = [NSAffineTransform transform];
NSSize dimensions = self.size;
[self lockFocus];
[flipper scaleXBy:-1.0 yBy:1.0];
[flipper set];
[self drawAtPoint:NSMakePoint(-dimensions.height,0)
fromRect:NSMakeRect(0,0, dimensions.width, dimensions.height)
operation:NSCompositeCopy fraction:1.0];
[self unlockFocus];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment