Post

Replies

Boosts

Views

Activity

Reply to PorterDuff.mode in Swift to colorize an image
Finally I got the next code which solves my problem:func nalaFilter() -> UIImage? { let brownColor = CIColor (red: 128.0/255.0, green: 0.0, blue: 0.0) let brownRect = CGRect (origin: .zero, size: self.size) //Colored image UIGraphicsBeginImageContextWithOptions(brownRect.size, true, 0.0) brownColor.setFill() UIRectFill(brownRect) let brownColoredImage = UIGraphicsGetImageFromCurrentImageContext() let brownContext = UIGraphicsGetCurrentContext() brownContext!.setFillColor(UIColor.white.cgColor) brownContext!.fill(brownRect) self.draw(in: brownRect, blendMode: .normal, alpha: 1) brownColoredImage?.draw(in: brownRect, blendMode: .colorDodge, alpha: 1) let outBrown0Image = UIGraphicsGetImageFromCurrentImageContext() //Multiplied image self.draw(in: brownRect, blendMode: .normal, alpha: 1) outBrown0Image?.draw(in: brownRect, blendMode: .multiply, alpha: 1) let outBrownImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return outBrownImage }This gets exactly the same result than my Android one.
Mar ’20