0
我的顏色爲255.0.180,我需要將此顏色轉換爲透明。當我使用白色,此代碼工作正常:在UIImage中將某些顏色更改爲透明
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!
當我使用相同的代碼colorMasking:222,255,222,0,255,180 - 不工作。 你能幫我嗎?
sry,我不知道你的意思? Iam在這個問題上是新的 – ankmara