首页 > 解决方案 > iOS Core Graphics如何将CGImage的中间行作为vImage_Buffer?

问题描述

我试图只处理一部分(不是完整的)CGImage。我有下面的代码,从 0 开始并获取整个图像缓冲区。我需要知道如何获取指向中间行的指针,所以我可以将它作为参数传入。

如何仅获得 CGImage 的中心字节行?

extension CGImage {

func processImage() -> UInt {

    guard let imgProvider: CGDataProvider = self.dataProvider,
    let imgBitmapData: CFData = imgProvider.data else {
        return 0
    }
    
    let topLeftPixelPointer = UnsafeMutableRawPointer(mutating: CFDataGetBytePtr(imgBitmapData))
    var imgBuffer = vImage_Buffer(data: topLeftPixelPointer,
                                  height: vImagePixelCount(height),
                                  width: vImagePixelCount(width),
                                  rowBytes: bytesPerRow)
    
    let specificAddressWithinBuffer = /*??*/ // I'm not sure how to set this to point to a specific row
    var sliceOfBuffer = vImage_Buffer(data: /**/,
                                  height: vImagePixelCount(height),
                                  width: vImagePixelCount(width),
                                  rowBytes: bytesPerRow)

   }
}

标签: ioscore-graphicsswift5cgimage

解决方案


推荐阅读