iphone - How do I determine the location of each pixel in a square drawn via Core Graphics? -


i trying each pixel point of square drawn using core graphics.here making stroke color black color,i drawing square.please give me idea how pixel point on square drawn.

- (void)drawrect:(cgrect)rect  {     cgmutablepathref path = cgpathcreatemutable();      cgcontextref ctx = uigraphicsgetcurrentcontext();      cgpathmovetopoint(path, null, 30.0f, 30.0f);     cgpathaddlinetopoint(path, null, 130.0f, 30.0f);     cgpathaddlinetopoint(path, null, 130.0f, 130.0f);     cgpathaddlinetopoint(path, null, 30.0f, 130.0f);     cgpathclosesubpath(path);     cgpathretain(path);     cgcontextsetfillcolorwithcolor(ctx, [uicolor clearcolor].cgcolor);      cgcontextsetstrokecolorwithcolor(ctx,[uicolor blackcolor].cgcolor);     cgcontextsetlinewidth(ctx, 2.0);     cgcontextsavegstate(ctx);     cgcontextaddpath(ctx, path);       cgcontextrestoregstate(ctx);     cgcontextstrokepath(ctx);     cgcontextrestoregstate(ctx);      cgcontextrestoregstate(ctx);     [self setneedsdisplay];     cgpathrelease(path); } 

why doing work instead of using cgcontextfillrect() , cgcontextstrokerect()?

your code above can simplified to:

cgrect r = cgrectmake(30.0, 30.0, 100.0, 100.0); cgcontextref ctx = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(ctx, cgcolorgetconstantcolor(kcgcolorclear)); cgcontextfillrect(ctx, r); cgcontextsetlinewidth(ctx, 2.0); cgcontextsetstrokecolorwithcolor(ctx, cgcolorgetconstantcolor(kcgcolorblack)); cgcontextstrokerect(ctx, r); 

also, never send -setneedsdisplay within -drawrect: method. you'll infinite loop.


Comments

Popular posts from this blog

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 -

openssl - Load PKCS#8 binary key into Ruby -