这是我的原始代码。
在这种情况下,在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)!)
...
但我无法显示我的形象。 我该怎么做才能解决这个问题?
答案 0 :(得分:0)
这是我的固定代码。
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)!)
我有一个参考链接