I am getting unsupported parameter combination CGBitmap error with swift

前端 未结 8 557
野趣味
野趣味 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:44

    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
        }
    
    0 讨论(0)
  • 2020-12-09 08:46

    CGBitmapInfo.AlphaInfoMask is not a valid bitmap info.

    Try setting CGBitmapInfo.AlphaLast or CGBitmapInfo.AlphaFirst.

    0 讨论(0)
提交回复
热议问题