Swift3 我能';我不能在swift 3中显示我的图像吗?

Swift3 我能';我不能在swift 3中显示我的图像吗?,swift3,uigraphicscontext,Swift3,Uigraphicscontext,这是我的原始代码 在本例中,在imageview中显示我的图像 let cgImge = self.test.image?.cgImage?.copy() self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!) 这是我在项目过程中的代码 ... UIGraphicsBeginImageConte

这是我的原始代码

在本例中,在imageview中显示我的图像

let cgImge = self.test.image?.cgImage?.copy()
self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!)
这是我在项目过程中的代码

...
UIGraphicsBeginImageContext((self.test.image?.size)!)
self.test.layer.render(in: UIGraphicsGetCurrentContext()!)
self.test.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let cgImge = self.test.image?.cgImage?.copy()
self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!)

但是我不能显示我的图像。 如何解决此问题?

这是我的修复代码

UIGraphicsBeginImageContextWithOptions(self.test.bounds.size, self.test.isOpaque, 0.0)
//UIGraphicsBeginImageContext((self.test.image?.size)!)
self.test.layer.render(in: UIGraphicsGetCurrentContext()!)
//self.test.image?.draw(at: self.test.frame)
let temp: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()

UIGraphicsBeginImageContextWithOptions(self.test.bounds.size, self.test.isOpaque, 1.0)
temp.draw(in: self.test.bounds)
let custom: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()

let cgImge = custom.cgImage?.copy(maskingColorComponents: [222,255,222,255,222,255])
self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!)
我有一个参考链接