Я не могу отобразить свое изображение в Swift 3?

Вот мой исходный код.

В этом случае отображает мое изображение в изображении.

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)!)

...

Но я не могу отобразить свое изображение. Что я могу сделать, чтобы решить эту проблему?


person Eric Chan    schedule 10.01.2017    source источник


Ответы (1)


Вот мой фиксированный код.

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)!)

Я получил реферальную ссылку

iOS: сохранить изображение с пользовательским разрешением

person Eric Chan    schedule 11.01.2017