iphone - How to get each pixel position (Coordinate) of a Hollow Character drawn using Core Graphics? -


i using uiview subclass draw alphabet using core graphics.using code hollow characters drwan(by making stroke color- black color).here need each pixel(coordinate) position of character.please give me idea how each pixel point(only black point's pixel value) of hollow character.

source code:

/*uiview subclass method*/  - (void)drawrect:(cgrect)rect {       //method draw alphabet       [self drawchar:@"a" xcoord:5 ycoords:35]; } -(void)drawchar:(nsstring *)str xcoord: (cgfloat)x ycoord: (cgfloat)y {      const char *text = [str utf8string];//getting alphabet     cgcontextref ctx = uigraphicsgetcurrentcontext();     cgcontextselectfont(ctx, "helvetica", 40.0, kcgencodingmacroman);     cgcontextsettextdrawingmode(ctx, kcgtextfillstroke);     cgcontextsetstrokecolorwithcolor(ctx, [uicolor blackcolor].cgcolor);//to make character hollow-need these points     cgcontextsetfillcolorwithcolor(ctx, [uicolor clearcolor].cgcolor);//fill color of character clear color      cgaffinetransform xform = cgaffinetransformmake(                                                     1.0,  0.0,                                                     0.0, -1.0,                                                     0.0,  0.0);//giving transformation alphabet      cgcontextsettextmatrix(ctx, xform);     cgcontextshowtextatpoint(ctx, x, y, text, strlen(text));//generating character } 

firstly, there's convenient method set fill , stroke color:

[[uicolor blackcolor] setstroke]; [[uicolor clearcolor] setfill]; 

either or use cgcontextsetgrayfillcolor , cgcontextsetgraystrokecolor.


as problem, pixel information, have use cgbitmapcontext. can bitmap cgbitmapcontextgetdata. suppose declare rgba bitmap, bitmap data arranged as

rgba_at_(0,0)  rgba_at_(1,0)  ...  rgba_at_(w,0)  rgba_at(0,1)  rgba_at_(1,1) ... 

therefore, can scan linearly target color values , determine black pixels.


please note uigraphicsgetcurrentcontext() not cgbitmapcontext, should not apply cgbitmapcontextgetdata on it. instead, have create own bitmap context cgbitmapcontextcreate, draw text onto bitmap context, obtain cgimage result cgbitmapcontextcreateimage, , draw cgimage onto uicontext.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -