2017-11-03 5 views
0

나는 UI에서 단색 이미지로 임의의 수있는 단일 색상 이미지로 표시해야 할 서버에서 오는 UIImage 있습니다. 그것을 달성하는 가장 좋은 방법은 무엇입니까?iOS에서 단색 UIImage를 만드는 방법

fileprivate func monochromaticImage(from image: UIImage, in color: UIColor) -> UIImage { 
    guard let img = CIImage(image: image) else { 
     return image 
    } 
    let color = CIColor(color: color) 
    guard let outputImage = CIFilter(name: "CIColorMonochrome", 
           withInputParameters: ["inputImage" : img, 
                "inputColor" : color])?.outputImage else { 
     return image 
    } 
    let context = CIContext() 
    if let cgImage = context.createCGImage(outputImage, from: outputImage.extent) { 
     let newImage = UIImage(cgImage: cgImage, scale: image.scale, orientation: image.imageOrientation) 
     return newImage 
    } 
    return image 
} 
: 내 현재의 방법에서

답변

1

나는 주어진 이미지와 색상의 단색 이미지를 반환하는 다음과 같은 방법을 사용하고 있습니다
관련 문제