views:

124

answers:

2

Hi,

I have a series of avatars; each has a hot pink background of RGB:255,0,255.

Rather than going through every avatar, and manually removing the pink background; is there a way to make Objective C remove the background (masking it) for me?

An example of an avatar follows:

alt text

One thing I am concerned about is that the masking is done on the fly, and may cost memory; is this something I should be concerned about?

Additionally, let's say I put the avatars in a spritesheet; could I apply the mask once and work with that?

Thanks for your help.

A: 

If you added the buttons programatically you could set a global NSArray and addObject:yourButton each time you make an avatar button, then when you want to remove the background do this:

for (UIButton *custom in globalButtonArray) {
    custom.backgroundColor = [UIColor clearColor];
}
Thomas Clayson
Just thinking acctually you would need an NSMutableArray... so you could add the buttons. :)
Thomas Clayson
Why should this work? The image have opaque pink areas. They completely cover everything that's underneath. Changing the background color of some UI element will have no effect. And why are you introducing buttons? What for?
Codo
Ah... i dunno why I said buttons, I meant UIImageView - apologies. Similarly, I just assumed that the purple background was programatically added. Otherwise I would assume the auhor would have called them "pink areas". I misunderstood.
Thomas Clayson
I still haven't been able to remove the background color. CGImageCreateWithMaskingColors does not have any source code examples, unlike the rest of the documentation on that page.
zardon
can you not just open the images in photoshop and make them pngs with transparency.
Thomas Clayson
+1  A: 

see function CGImageCreateWithMaskingColors. I think this is what you need. See reference: Masking an Image With Color

Nava Carmon
Oh, thanks for your help. I will review this further.
zardon