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

标签 ios image swift uiimageview analysis

我有以下快速代码。

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/

相关文章:

ios - 带有按钮的 UIAlertView,标题重叠?

image - 为什么我在 Delphi 2009 功能区中使用的透明图像在运行时不透明?

ios - 如何根据其中的内容创建具有动态高度的collectionview?

objective-c - UISegmentedController 内的可编辑文本

ios - Facebook Audience Network 在 XCode 7 上有太多警告

javascript - 如何用js将<svg>标签改为<img>标签?

ios - 如何让这个淡入淡出动画起作用?

ios - Swift:在 TableView 单元格中创建 UILabel

swift - 如何在 Snippet Google Maps Swift 上显示用户的位置

ios - (Swift) 如何打印字符串中的 "\"字符?