添加到@ Horray的答案,要獲得顏色值,你必須再執行兩行。只要檢查該實現,
var pixel : [UInt8] = [0, 0, 0, 0]
var colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(UnsafeMutablePointer(pixel), 1, 1, 8, 4, colorSpace, bitmapInfo)
// Translate the context your required point(x,y)
CGContextTranslateCTM(context, -x, -y);
yourImageView.layer.renderInContext(context)
NSLog("pixel: %d %d %d %d", pixel[0], pixel[1], pixel[2], pixel[3]);
let redColor : Float = Float(pixel[0])/255.0
let greenColor : Float = Float(pixel[1])/255.0
let blueColor: Float = Float(pixel[2])/255.0
let colorAlpha: Float = Float(pixel[3])/255.0
// Create UIColor Object
var color : UIColor! = UIColor(red: CGFloat(redColor), green: CGFloat(greenColor), blue: CGFloat(blueColor), alpha: CGFloat(colorAlpha))
參考此答案http://stackoverflow.com/questions/3284185/get-pixel-color-of-uiimage –