我有以下快速代码。
let resolution = [imageView.frame.size.width, imageView.frame.size.height]
for x in 0...Int(resolution[0]) {
for y in 0...Int(resolution[1]) {
let coordinate = [x, y]
//Find the colour of the pixel here
}
}
我希望能够找到照片中每个像素所显示的颜色。有没有办法修改我放置“//在此处查找像素的颜色”的代码,使其打印常量坐标表示的坐标处像素的 RGB 值?
最佳答案
您可以尝试以下方法:
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)
希望这对您有所帮助!
关于ios - 如何快速查找 UIImage 中单个像素的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29813796/