MB.
MB.

Reputation: 4211

CGImageCreateWithMaskingColors leaving border when removing color

I'm using the code below to make the color magenta transparent:

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.

The result is an image that has magenta borders: https://i.sstatic.net/kWEXH.png. The borders are present before adding the alpha channel, so it's not related to that.

Is it possible to get rid of those borders?

Upvotes: 4

Views: 1895

Answers (2)

jon_junay
jon_junay

Reputation: 47

CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), NO);

It will be ok.

Upvotes: 3

MB.
MB.

Reputation: 4211

The problem was in the mask I was building. Setting antialias to off fixed the issue.

Upvotes: 0

Related Questions