Skip to content

Instantly share code, notes, and snippets.

View rishigesh's full-sized avatar

Rishigesh Murugesh rishigesh

  • Munich
View GitHub Profile
@rishigesh
rishigesh / gist:e09bc943ef1e83852c2ac21c3e1b1f35
Created March 17, 2017 15:26
NSImage Mask image with NSColor (Swift)
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)
@rishigesh
rishigesh / gist:fc66a2cb35372b2aa011a7a69f606d40
Created March 17, 2017 15:24
NSImage Flip Horizontally (Swift)
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)