小编Nei*_*Lee的帖子

在Swift 3中使用CGPoint从图像中获取像素颜色

我在Swift 3中尝试这个PixelExtractor类,得到一个错误; 无法使用类型'(UnsafeMutableRawPointer?)'的参数列表调用类型'UnsafePointer'的初始值设定项

class PixelExtractor: NSObject {

let image: CGImage
let context: CGContextRef?

var width: Int {
    get {
        return CGImageGetWidth(image)
    }
}

var height: Int {
    get {
        return CGImageGetHeight(image)
    }
}

init(img: CGImage) {
    image = img
    context = PixelExtractor.createBitmapContext(img)
}

class func createBitmapContext(img: CGImage) -> CGContextRef {

    // Get image width, height
    let pixelsWide = CGImageGetWidth(img)
    let pixelsHigh = CGImageGetHeight(img)

    let bitmapBytesPerRow = pixelsWide * 4
    let bitmapByteCount = bitmapBytesPerRow * Int(pixelsHigh)

    // Use the generic RGB …
Run Code Online (Sandbox Code Playgroud)

image pixel cgpoint swift3

3
推荐指数
1
解决办法
5939
查看次数

标签 统计

cgpoint ×1

image ×1

pixel ×1

swift3 ×1