Skip to content

Instantly share code, notes, and snippets.

View mikgr's full-sized avatar
😜

Mikkel Gautier Roesen mikgr

😜
View GitHub Profile
@jeanetienne
jeanetienne / NSImage+RoundedCorners.swift
Last active January 18, 2024 21:28
Drawing an NSImage with rounded corners in Swift
// This extension is a port of @venj's solution from 2011
// https://github.com/venj/Cocoa-blog-code/blob/master/Round%20Corner%20Image/Round%20Corner%20Image/NSImage%2BRoundCorner.m
extension NSImage {
func roundCorners(withRadius radius: CGFloat) -> NSImage {
let rect = NSRect(origin: NSPoint.zero, size: size)
if
let cgImage = self.cgImage,
let context = CGContext(data: nil,