我希望能将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 };
请问有人能帮忙解决如何将颜色变为透明的问题吗?