我正在基于基于 DeviceGray 颜色空间的图像创建 mask 。
基本上我想做的是将各种灰色(除了黑色)像素更改为白色,并保持黑色像素不变。
所以我希望我的图像由黑白像素组成。
知道如何使用 CoreGraphics 实现吗?
请不要在循环中遍历所有像素
最佳答案
像这样一起使用 CGImageCreateWithMaskingColors
和 CGContextSetRGBFillColor
:
CGImageRef myMaskedImage;
const CGFloat myMaskingColors[6] = { 0, 124, 0, 68, 0, 0 };
myColorMaskedImage = CGImageCreateWithMaskingColors (image,
myMaskingColors);
CGContextSetRGBFillColor (myContext, 0.6373,0.6373, 0, 1);
CGContextFillRect(context, rect);
CGContextDrawImage(context, rect, myColorMaskedImage);
顺便说一下,CGImageCreateWithMaskingColors 中提到了填充颜色讨论。
关于iphone - 改变色彩空间和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10708656/