I am getting unsupported parameter combination CGBitmap error with swift

前端 未结 8 562
野趣味
野趣味 2020-12-09 08:16

I am trying to create a CGContext in swift. It compiles but throws an error at runtime.

let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let conte         


        
8条回答
  •  温柔的废话
    2020-12-09 08:24

    Just in case somebody is running into the same problem. The snippet below finally works.

    let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
    let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
    let context = CGBitmapContextCreate(nil, UInt(rect.size.width), UInt(rect.size.height), 8, 0, colorSpace, bitmapInfo)
    

    It generates a 32 bit RGBA context in swift

提交回复
热议问题