I am getting unsupported parameter combination CGBitmap error with swift

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

    I had some issues in Swift 1.2 using UInt, now I'm using Int and it's working. This Example shows how to convert an Image to a grayscale image.

    let imageRect = self.myImage.frame
    
    let colorSpace = CGColorSpaceCreateDeviceGray()
    let width = imageRect.width
    let height = imageRect.height
    
    let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.None.rawValue)
    let context = CGBitmapContextCreate(nil, Int(width), Int(height), 8, 0, colorSpace, bitmapInfo)
    

提交回复
热议问题