我想将 UIimage 中的颜色更改为透明我正在使用下面的代码将黑色更改为透明
-(void)changeColorToTransparent: (UIImage *)image{
CGImageRef rawImageRef = image.CGImage;
const float colorMasking[6] = { 0, 0, 0, 0, 0, 0 };
UIGraphicsBeginImageContext(image.size);
CGImageRef 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);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
CGImageRelease(maskedImageRef);
UIGraphicsEndImageContext();
}
它工作正常..但我想通过选择颜色形式的颜色选择器在图像上画一个点,然后想让那个点透明..我不知道如何在下面的行中给出颜色遮罩的值
const float colorMasking[6] = { 0, 0, 0, 0, 0, 0 };
任何人都可以帮助我如何使颜色变为透明