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?
The problem was in the mask I was building. Setting antialias to off fixed the issue.