2017-01-10 1 views
0

Voici mon code original.Je ne peux pas afficher mon image dans swift 3?

Dans ce cas, affiche mon image en mode image.

let cgImge = self.test.image?.cgImage?.copy() 
self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!) 

Voici mon code pendant le processus d'un projet.

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

...

Mais je ne peux pas afficher mon image. Que puis-je faire pour résoudre ce problème?

Répondre

0

Voici mon code fixe.

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

J'ai obtenu un lien de référence

iOS : Save image with custom resolution