Skip to content

Instantly share code, notes, and snippets.

View gbrl0chn's full-sized avatar

gbrl0chn

  • Taiwan
View GitHub Profile
@gbrl0chn
gbrl0chn / NSImageExtension.swift
Created June 15, 2018 07:18 — forked from DennisWeidmann/NSImageExtension.swift
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),