CGImageCreateWithMaskingColors在删除颜色时留下边框

时间:2011-11-30 03:21:47

标签: ios uiimage cgimage

我正在使用下面的代码使颜色洋红色透明:

UIImage *inputImage = [UIImage imageWithData:UIImageJPEGRepresentation(anchorWithMask, 1.0)];

const float colorMasking[6] = {0.0, 255.0, 0.0, 2.0, 0.0, 255.0};
CGImageRef imageRef = CGImageCreateWithMaskingColors(inputImage.CGImage, colorMasking);

UIImage *image = [UIImage imageWithCGImage:imageRef];

// add an alpha channel to the image.

结果是具有洋红色边框的图像:http://i.imgur.com/4g6lM.png。在添加Alpha通道之前存在边框,因此它与此无关。

是否有可能摆脱这些边界?

2 个答案:

答案 0 :(得分:3)

CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), NO);

没关系。

答案 1 :(得分:0)

问题在于我正在建造的面具。将antialias设置为off可以解决问题。