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
func mask(color: NSColor) -> NSImage { | |
let imageRect = CGRect(x: CGFloat(0.0), y: CGFloat(0.0), width: CGFloat(self.size.width), height: CGFloat(self.size.height)) | |
var newImage:NSImage? = nil | |
let context = IOSXGraphicsBeginImageContextWithOptions(imageRect.size, false, 1.0) | |
context.clip(to: imageRect, mask: self.cgImage!) | |
context.setFillColor(color.cgColor) | |
context.setBlendMode(.difference) | |
context.fill(imageRect) |
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
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) |