Created
March 17, 2017 15:24
-
-
Save rishigesh/fc66a2cb35372b2aa011a7a69f606d40 to your computer and use it in GitHub Desktop.
NSImage Flip Horizontally (Swift)
This file contains 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
public func flipHorizontally() -> IOSXImage { | |
let existingImage: NSImage? = self | |
let existingSize: NSSize? = existingImage?.size | |
let newSize: NSSize? = NSMakeSize((existingSize?.width)!, (existingSize?.height)!) | |
let flipedImage = NSImage(size: newSize!) | |
flipedImage.lockFocus() | |
let t = NSAffineTransform.init() | |
t.translateX(by: (existingSize?.width)!, yBy: 0.0) | |
t.scaleX(by: -1.0, yBy: 1.0) | |
t.concat() | |
let rect:NSRect = NSMakeRect(0, 0, (newSize?.width)!, (newSize?.height)!) | |
existingImage?.draw(at: NSZeroPoint, from: rect, operation: .sourceOver, fraction: 1.0) | |
flipedImage.unlockFocus() | |
return flipedImage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment