Created
February 8, 2013 05:52
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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