2017-01-10 1 views
0

내 원본 코드는 다음과 같습니다.스위프트 3에서 내 이미지를 표시 할 수 없습니까?

이 경우 이미지를 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

여기 내 고정 코드입니다.

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 : Save image with custom resolution

관련 문제