I am sure that the answer for this exists in stackoverflow, but I searched and could not find it yet. In fact, I have several images with a transparent background and some black images, I want to be able to change the color of the black part to some other arbitrary color.
I'm sure this is possible with Quartz Image Masking , but I could not find any good examples, so this is what I am looking for. Other solutions are also welcome.
Thanks!!!
UPDATE: I think I'm very close with this code ... but my mask does not work. However, my UIView filled with fill color, but it's just a giant rectangle that doesn't get cropped.
UPDATE # 2: I'm even closer (I think) with the following code. The problem is that my background is now black, not transparent.
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -rect.size.height); CGImageRef maskImage = [self.image CGImage]; CGContextClipToMask(context, rect, maskImage); [_colorToChangeInto setFill]; CGContextFillRect(context, rect);
source share