Changing color space on and image

2019-03-03 20:42发布

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条回答
闹够了就滚
2楼-- · 2019-03-03 21:18

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.

查看更多
登录 后发表回答