Skip to content

Instantly share code, notes, and snippets.

View DennisWeidmann's full-sized avatar

Dennis Weidmann DennisWeidmann

View GitHub Profile
@DennisWeidmann
DennisWeidmann / NSImageExtension.swift
Last active January 9, 2023 10:10
Convert NSImage to CVPixelBuffer
extension NSImage {
func pixelBuffer() -> CVPixelBuffer? {
let width = self.size.width
let height = self.size.height
let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
var pixelBuffer: CVPixelBuffer?
let status = CVPixelBufferCreate(kCFAllocatorDefault,
Int(width),
Int(height),