我正在尝试使用核心图像和CIFilter来改变图像中的视角。但是在将CIImage转换为UIImage后,我的图像是黑色的。
let perspectiveTransform = CIFilter(name: "CIPerspectiveTransform")!
let composite = CIFilter(name: "CISourceAtopCompositing")!
let backgroundImage = CIImage(image: UIImage(named: "interior0.jpg")!)!
let clearImage = CIImage(image: UIImage(named: "clear.png")!)!
perspectiveTransform.setValue(CIVector(x: CGFloat(perspectiveValues["inputTopLeftVectorX"]!), y: CGFloat(perspectiveValues["inputTopLeftVectorY"]!)),
forKey: "inputTopLeft")
perspectiveTransform.setValue(CIVector(x: CGFloat(perspectiveValues["inputTopRightVectorX"]!), y: CGFloat(perspectiveValues["inputTopRightVectorY"]!)),
forKey: "inputTopRight")
perspectiveTransform.setValue(CIVector(x: CGFloat(perspectiveValues["inputBottomRightVectorX"]!), y: CGFloat(perspectiveValues["inputBottomRightVectorY"]!)),
forKey: "inputBottomRight")
perspectiveTransform.setValue(CIVector(x: CGFloat(perspectiveValues["inputBottomLeftVectorX"]!), y: CGFloat(perspectiveValues["inputBottomLeftVectorY"]!)),
forKey: "inputBottomLeft")
perspectiveTransform.setValue(CIImage(image: (imageView?.image)!),
forKey: kCIInputImageKey)
let topImage = UIImage(CIImage: backgroundImage)
当我将topImage
设置为imageView?.image
时,它会显示黑色图像。
任何人都知道如何解决它?