iphone - Is there an SDK to draw lines on iOS with touch? -


is there framework can use draw lines touch. want add ability customer sign on ipad/iphone , capture image.

any appreciated.

thanks.

you can meet requirement using core graphics available in uikit framework.

i had similar requirement in application different use ,if needed can provide code.

tnq

.h file

#import <uikit/uikit.h> typedef enum _drawingmode{ drawingmodepen =0, drawingmodeeraser=1, } drawingmode; @interface drawingview : uiview { cgpoint lastpoint; uiimageview *drawimage; bool mouseswiped;    int mousemoved; drawingmode mode; uicolor *_drawingpencolor; } @property (nonatomic, retain) uicolor *drawingpencolor; @property (nonatomic) drawingmode mode;  @property (nonatomic, retain) uiimageview *imageview; @property (nonatomic,retain)uiimageview *drawimage; @end 

.m

#import "drawingview.h"   @implementation drawingview  @synthesize mode, drawingpencolor=_drawingpencolor, imageview=drawimage;   -(void)initialize{     drawimage = [[uiimageview alloc] initwithimage:nil];     self.autoresizessubviews = yes;     drawimage.autoresizingmask = (uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight);     drawimage.frame = self.bounds;     [self addsubview:drawimage];     self.backgroundcolor = [uicolor clearcolor];     mousemoved = 0;     _drawingpencolor = [[uicolor alloc] initwithwhite:0.0 alpha:1.0]; }  -(void)maskimage:(uiimage *)image withmask:(uiimage *)maskimage  {     cgimageref maskref = maskimage.cgimage;      cgimageref mask = cgimagemaskcreate(cgimagegetwidth(maskref),                                         cgimagegetheight(maskref),                                         cgimagegetbitspercomponent(maskref),                                         cgimagegetbitsperpixel(maskref),                                         cgimagegetbytesperrow(maskref),                                         cgimagegetdataprovider(maskref), null, false);     cgimageref masked = cgimagecreatewithmask([image cgimage], mask);     uiimage *tempimage = [[uiimage alloc] initwithcgimage:masked];     //self.clippedimage = tempimage;     [tempimage release];     cfrelease(masked);     cfrelease(mask); }  -(void)awakefromnib{     [self initialize]; }  - (id)initwithframe:(cgrect)frame {     if ((self = [super initwithframe:frame])) {         // initialization code         [self initialize];     }     return self; }  - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {      mouseswiped = no;     uitouch *touch = [touches anyobject];      if ([touch tapcount] == 2) {         drawimage.image = nil;         return;     }      lastpoint = [touch locationinview:self];     //lastpoint.y -= 20;     nslog(@"touches begin");  }  - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event {     mouseswiped = yes;      uitouch *touch = [touches anyobject];        cgpoint currentpoint = [touch locationinview:self];     //currentpoint.y -= 20;       uigraphicsbeginimagecontext(self.bounds.size);     [drawimage.image drawinrect:cgrectmake(0, 0, self.bounds.size.width, self.bounds.size.height)];     cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround);     cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), 5.0);     if (mode == drawingmodepen) {         nslog(@"drawing");         cgcontextsetstrokecolorwithcolor(uigraphicsgetcurrentcontext(), [_drawingpencolor cgcolor]);     }     else {         cgcontextsetstrokecolorwithcolor(uigraphicsgetcurrentcontext(), [[uicolor clearcolor] cgcolor]);          cgcontextbeginpath(uigraphicsgetcurrentcontext());           cgcontextmovetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y);         cgcontextclearrect (uigraphicsgetcurrentcontext(), cgrectmake(lastpoint.x, lastpoint.y, 20, 20));         cgcontextstrokepath(uigraphicsgetcurrentcontext());          nslog(@"clearing");             }     cgcontextbeginpath(uigraphicsgetcurrentcontext());     cgcontextmovetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y);     cgcontextaddlinetopoint(uigraphicsgetcurrentcontext(), currentpoint.x, currentpoint.y);     cgcontextstrokepath(uigraphicsgetcurrentcontext());     drawimage.image = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();      lastpoint = currentpoint;      mousemoved++;      if (mousemoved == 10) {         mousemoved = 0;     }  }  - (void)touchesended:(nsset *)touches withevent:(uievent *)event {      uitouch *touch = [touches anyobject];      if ([touch tapcount] == 2) {         drawimage.image = nil;         return;     }       if(!mouseswiped) {         uigraphicsbeginimagecontext(self.bounds.size);         [drawimage.image drawinrect:cgrectmake(0, 0, self.bounds.size.width, self.bounds.size.height)];         cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround);         cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), 5.0);         cgcontextmovetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y);         cgcontextaddlinetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y);         if (mode == drawingmodepen) {             cgcontextsetstrokecolorwithcolor(uigraphicsgetcurrentcontext(), [_drawingpencolor cgcolor]);         }         else {             cgcontextsetstrokecolorwithcolor(uigraphicsgetcurrentcontext(), [self.backgroundcolor cgcolor]);         }         cgcontextstrokepath(uigraphicsgetcurrentcontext());         cgcontextflush(uigraphicsgetcurrentcontext());         drawimage.image = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();     } }  - (void)dealloc {     [drawimage release];     [_drawingpencolor release];     [super dealloc]; }  @end 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -