次のように、現在の描画可能なテクスチャから UIImage を作成しています。
func createImageFromCurrentDrawable() ->(UIImage){
let context = CIContext()
let texture = metalView.currentDrawable!.texture
let kciOptions = [kCIContextWorkingColorSpace: CGColorSpace(name: CGColorSpace.sRGB)!,
kCIContextOutputPremultiplied: true,
kCIContextUseSoftwareRenderer: false] as [String : Any]
let cImg = CIImage(mtlTexture: texture, options: kciOptions)!
let cgImg = context.createCGImage(cImg, from: cImg.extent)!
let uiImg = UIImage(cgImage: cgImg)
return uiImg
}
しかし、テクスチャに表示されていない UIImage にアルファ値を追加します。アルファを取り除く解決策はありますか? これがキャプチャされたテクスチャ画像です。
テクスチャから作成された uiImage。