In case anyone else ends up here, I got to a drawing context using this code...
private func createDummyImage(size: CGSize) -> CGImage {
let pixelsWide = Int(size.width)
let pixelsHigh = Int(size.height)
let bitmapBytesPerRow = pixelsWide * 4
let bufferLength = Int(size.width * size.height * 4)
let bitmapData: CFMutableData = CFDataCreateMutable(nil, 0)
CFDataSetLength(bitmapData, CFIndex(bufferLength))
let bitmap = CFDataGetMutableBytePtr(bitmapData)
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
let context = CGContext(data: bitmap,
width: pixelsWide,
height: pixelsHigh,
bitsPerComponent: 8,
bytesPerRow: bitmapBytesPerRow,
space: colorSpace,
bitmapInfo: bitmapInfo.rawValue)
Once I drew the content, I got a CGImage using:
let image = context.makeImage()
Once I had that, I could convert to an NSImage for display on the screen. Loads of error handling to be added at some stage. For now, I'm only prototyping the code, so want the crashes to see what can go wrong.