I have a series of avatars; each has a hot pink background of RGB:255,0,255.
我有一系列的化身;每个都有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?
而不是遍历每一个头像,手动删除粉色背景;有没有办法让Objective - C去掉背景(蒙版)?
An example of an avatar follows:
一个化身的例子如下:
alt text http://img39.imageshack.us/img39/2645/bluegem.png
alt文本http://img39.imageshack.us/img39/2645/bluegem.png
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?
另外,假设我把化身放在spritesheet中;我可以使用一次蒙版吗?
Thanks for your help.
谢谢你的帮助。
2 个解决方案
#1
3
see function CGImageCreateWithMaskingColors. I think this is what you need. See reference: Masking an Image With Color
看到CGImageCreateWithMaskingColors函数。我想这就是你需要的。见参考:用颜色遮蔽图像
#2
0
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:
如果你按程序添加按钮,你可以设置全局的NSArray和addObject:yourButton每当你创建一个头像按钮,那么当你想要删除背景时,你可以这样做:
for (UIButton *custom in globalButtonArray) {
custom.backgroundColor = [UIColor clearColor];
}
#1
3
see function CGImageCreateWithMaskingColors. I think this is what you need. See reference: Masking an Image With Color
看到CGImageCreateWithMaskingColors函数。我想这就是你需要的。见参考:用颜色遮蔽图像
#2
0
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:
如果你按程序添加按钮,你可以设置全局的NSArray和addObject:yourButton每当你创建一个头像按钮,那么当你想要删除背景时,你可以这样做:
for (UIButton *custom in globalButtonArray) {
custom.backgroundColor = [UIColor clearColor];
}