0

I'm working with this excellent example of converting an image to grayscale: Convert Image to B&W problem CGContext - iPhone Dev

However, for my purposes, I would like to have only pure black and pure white left in the image.

It appears that to do so, I need to pass a black and white color space to the recolor method using a call:

CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(/*black and white name*/);

However, I was unable to find the proper iOS color space names. What I found was from Mac, and the "color space names" referenced from the iOS docs does not point anywhere.

How can I properly create a black and white CGColorSpaceRef?

Thank you!

4

2 回答 2

2

我不熟悉只有黑白的颜色空间,但你可以做的是计算所有像素的总平均 RGB 值(让我们称之为totalAvg)并将其用作阈值。如果每个像素的 rgb 平均值大于计算值totalAvg,则将其设置为纯白色,否则将其设置为纯黑色。

我同意这需要更多的工作,但这就是我能想到的,除非你找到你正在寻找的色彩空间。

于 2012-06-04T14:59:36.850 回答
2

您可以尝试创建一个灰色空间,然后使用两种颜色(显然是黑色和白色)创建一个索引颜色空间并使用它。

于 2012-06-04T18:30:59.393 回答