0

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

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

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

1 回答 1

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:函数是您在上面指定的)

于 2013-03-13T10:28:27.590 回答