gpt4 book ai didi

ios - 如何快速查找 UIImage 中单个像素的颜色

转载 作者:搜寻专家 更新时间:2023-10-31 08:27:01 25 4
gpt4 key购买 nike

我有以下快速代码。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com