我正在尝试使用金属拉普拉斯算子从 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 上: …