+2  A: 

Firstly, there's convenient method to set the fill and stroke color:

[[UIColor blackColor] setStroke];
[[UIColor clearColor] setFill];

either that or use CGContextSetGrayFillColor and CGContextSetGrayStrokeColor.


As for your problem, to get pixel information, you have to use a CGBitmapContext. You can get the bitmap by CGBitmapContextGetData. Suppose you declare an RGBA bitmap, the bitmap data will be arranged as

RGBA_at_(0,0)  RGBA_at_(1,0)  ...  RGBA_at_(w,0)  RGBA_at(0,1)  RGBA_at_(1,1) ...

therefore, you can scan linearly for any target color values and determine the black pixels.


Please note that UIGraphicsGetCurrentContext() is not necessarily a CGBitmapContext, so you should not apply CGBitmapContextGetData on it. Instead, you have to create your own bitmap context with CGBitmapContextCreate, draw the text onto this bitmap context, obtain the CGImage result by CGBitmapContextCreateImage, and finally draw this CGImage onto the UIContext.

KennyTM