[英]change some color to transparent in UIImage
i have color 255.0.180 and i need to convert this color to transparent. 我的颜色为255.0.180,我需要将此颜色转换为透明。 When i use white color, this code works fine:
当我使用白色时,此代码可以正常工作:
image = UIImage(data: UIImageJPEGRepresentation(image, 1.0)!)!
let rawImageRef: CGImageRef = image.CGImage!
let colorMasking: [CGFloat] = [222, 255, 222, 255, 222, 255]
// 222.0/255.0, 255.0/255.0,
UIGraphicsBeginImageContext(image.size);
let maskedImageRef=CGImageCreateWithMaskingColors(rawImageRef, colorMasking);
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0.0, image.size.height);
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height), maskedImageRef);
let result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result!
when i use same code with colorMasking: 222, 255, 222, 0, 255, 180 - doesn't work. 当我使用与colorMasking相同的代码时:222、255、222、0、255、180-不起作用。 Can you help me, please?
你能帮我吗?
也许如果您愿意,可以只调用此UIColor.clearColor(),这将为您提供透明的颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.