cgimagecreatewithmaskingcolors将所有透明区域更改为黑色

时间:2013-02-22 06:06:15

标签: ios uiimage core-graphics

我正在使用CGImageCreateWithMaskingColors()UIImage中移除特定颜色。颜色去除过程工作正常,但在屏蔽过程后图像中的透明区域变黑。请参阅下面粘贴的代码。

CGImageRef imageRef = self.editedImage.CGImage;
CGImageRef myColorMaskedImage = CGImageCreateWithMaskingColors(imageRef, myMaskingColors);

UIImage *newImage = [self normalizeWithAlpha:[UIImage imageWithCGImage:myColorMaskedImage]];
CGImageRelease(myColorMaskedImage);

1 个答案:

答案 0 :(得分:0)

你必须做第二次掩蔽传递来掩盖黑色:

    float colorMaskingLow[6] = {0, low, 0, low, 0, low};
    float colorMaskingHigh[6] = {high, 255, high, 255, high, 255};

    UIImage *image = [self maskColors:colorMaskingHigh inImage:image];
    return [self maskColors:colorMaskingLow inImage:image];

maskColors:inImage:函数是您在上面指定的函数)