小编use*_*656的帖子

通过 Apple-Metal MPSImageLaplacian 生成拉普拉斯图像

我正在尝试使用金属拉普拉斯算子从 rgb CGImage 生成拉普拉斯算子图像。

当前使用的代码:

if let croppedImage = self.cropImage2(image: UIImage(ciImage: image), rect: rect)?.cgImage {

  let commandBuffer = self.commandQueue.makeCommandBuffer()!

  let laplacian = MPSImageLaplacian(device: self.device)

  let textureLoader = MTKTextureLoader(device: self.device)

  let options: [MTKTextureLoader.Option : Any]? = nil

  let srcTex = try! textureLoader.newTexture(cgImage: croppedImage, options: options)

  let desc = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: srcTex.pixelFormat, width: srcTex.width, height: srcTex.height, mipmapped: false)

  let lapTex = self.device.makeTexture(descriptor: desc)

  laplacian.encode(commandBuffer: commandBuffer, sourceTexture: srcTex, destinationTexture: lapTex!)

  let output = CIImage(mtlTexture: lapTex!, options: [:])?.cgImage

  print("output: \(output?.width)")


  print("") 
}
Run Code Online (Sandbox Code Playgroud)

我怀疑问题出在 makeTexture 上: …

ios swift metal

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

标签 统计

ios ×1

metal ×1

swift ×1