2012-05-22 70 views
0

我正在創建一個基於DeviceGray色彩空間的圖像基於掩膜。更改顏色空間和圖像

基本上我想要做的是將各種灰色(黑色)像素變成白色,並保留黑色像素。

所以我希望我的圖像包含黑白像素。

任何想法如何實現使用CoreGraphics意味着什麼?

請不要報價在循環

回答

2

在像素上所有正在運行的應用CGImageCreateWithMaskingColorsCGContextSetRGBFillColor這樣在一起:

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討論中提到。

+0

我已經在我的照片上應用了這裏提供的代碼,但我仍然得到灰色像素,我需要保留黑色像素並將灰色像素上的各種顏色轉換爲白色。 – deimus

+0

@deimus您應該更改片段中的顏色範圍和填充顏色,您是否這樣做? –

+0

對不起,我只是太小,但在石英:),只是爲了確認下面的範圍權利,以獲得所有灰色旁邊黑色{1,255,1,255,1,255} – deimus