let size = CGSize(width: 200, height: 200)
// 开启上下文
UIGraphicsBeginImageContext(size)
// 获取当前的上下文
let context = UIGraphicsGetCurrentContext()
originImgView.image?.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let redColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.5)
context?.setFillColor(redColor.cgColor)
context?.setBlendMode(CGBlendMode.normal)
context?.fill(CGRect(x: 0, y: 0, width: size.width, height: size.height))
if let cgimg = context?.makeImage() {
resultImgView.image = UIImage(cgImage: cgimg)
}
网友评论