Wednesday, 15 February 2012

iphone - Undo CGContext lines -



iphone - Undo CGContext lines -

i know kind of post asked lot of time, searched lot on google , on site too, without finding solution, that's why i'm posting question. undo cgcontext line draw, without using uibezierpath or else. there way ? here code utilize draw:

- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; cgpoint currentpoint = [touch locationinview:mainimageview]; uigraphicsbeginimagecontext(mainimageview.frame.size); [mainimageview.image drawinrect:cgrectmake(0, 0, mainimageview.frame.size.width, mainimageview.frame.size.height)]; cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround); cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), dimension); const cgfloat *components = cgcolorgetcomponents([color cgcolor]); cgcontextsetrgbstrokecolor(uigraphicsgetcurrentcontext(), components[0], components[1], components[2], components[3]); cgcontextbeginpath(uigraphicsgetcurrentcontext()); cgcontextmovetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y); cgcontextaddlinetopoint(uigraphicsgetcurrentcontext(), currentpoint.x, currentpoint.y); cgcontextstrokepath(uigraphicsgetcurrentcontext()); mainimageview.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); lastpoint = currentpoint;}

thanks.

to add together undo:

you can't reveal info in image 1 time it's been painted over...

you'll either have maintain copies of image each time it's changed (lots of memory, although reduced perhaps keeping copies of changed areas only) or, maintain record of user's drawing steps , replay them after undo.

iphone objective-c draw cgcontext undo

No comments:

Post a Comment