Changing color space on and image

隐身守侯 提交于 2019-12-02 16:43:16

问题


I'm creating a mask based on DeviceGray color space based image.

What basically I want to do is to change all sorts of gray (beside black) pixels into white and leave black pixels as they are.

So I want my image to be consisted with black and white pixels.

Any idea how to achieve that using CoreGraphics means ?

Please dont offer running all over the pixels in the loop


回答1:


Use CGImageCreateWithMaskingColors and CGContextSetRGBFillColor together like this:

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);

By the way, the fill color is mentioned at the CGImageCreateWithMaskingColors discussion.



来源:https://stackoverflow.com/questions/10708656/changing-color-space-on-and-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!