0

I am having issues with trying to determine the colour of a location in an image when I provide the coordinates to this function

 func getColourFromPoint(point:CGPoint) -> UIColor {
    let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()!
    let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
    var pixelData:[UInt8] = [0, 0, 0, 0]
    let context = CGBitmapContextCreate(&pixelData, 1, 1, 8, 4, colorSpace, bitmapInfo)
    CGContextTranslateCTM(context, -point.x, -point.y);
    self.layer.renderInContext(context)

    var red:CGFloat = CGFloat(pixelData[0])/CGFloat(255.0)
    var green:CGFloat = CGFloat(pixelData[1])/CGFloat(255.0)
    var blue:CGFloat = CGFloat(pixelData[2])/CGFloat(255.0)
    var alpha:CGFloat = CGFloat(pixelData[3])/CGFloat(255.0)

    var color:UIColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)
    return color
}

What I get is an error "Cannot convert value of type 'CGBitmapInfo' to expected argument type 'UInt32'

As far as I can tell, bitmapInfo is UInt32 so I am stumped.

Stewart Lynch
  • 875
  • 9
  • 26

1 Answers1

0

It seems to be a struct conforming to OptionSetType now. Try rawValue...

let context = CGBitmapContextCreate(&pixelData, 1, 1, 8, 4, colorSpace, bitmapInfo.rawValue)
MirekE
  • 11,515
  • 5
  • 35
  • 28