I am trying to create a CGContext in swift. It compiles but throws an error at runtime.
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let conte
Updated for Swift 3:
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
guard let context = CGContext.init(data: nil, width: Int(size.width), height: Int(size.height), bitsPerComponent: Int(bitsPerComponent), bytesPerRow: Int(bytesPerRow), space: colorSpace, bitmapInfo: UInt32(bitmapInfo.rawValue)) else {
// cannot create context - handle error
}
CGBitmapInfo.AlphaInfoMask is not a valid bitmap info.
Try setting CGBitmapInfo.AlphaLast or CGBitmapInfo.AlphaFirst.