image - how to convert UIView part as UIImage in iphone application -


i have application in getting sign user finger works fine want signature should converted image , should display in imageview here code signature coding.

signature working fine , shows on view want convert graphics line image , display in imageview.

   #import <uikit/uikit.h>    @interface mylinedrawingview : uiview {    uibezierpath *mypath;   uicolor *brushpattern;   }    @end 

implementation classs

   #import "mylinedrawingview.h"    @implementation mylinedrawingview    - (id)initwithframe:(cgrect)frame   {   self = [super initwithframe:frame];  if (self) {     // initialization code      self.backgroundcolor=[uicolor whitecolor];     mypath=[[uibezierpath alloc]init];     mypath.linecapstyle=kcglinecapround;     mypath.miterlimit=0;     mypath.linewidth=10;     brushpattern=[uicolor redcolor];     }     return self;     } 

// override drawrect: if perform custom drawing. // empty implementation adversely affects performance during animation.

- (void)drawrect:(cgrect)rect {  [brushpattern setstroke];  [mypath strokewithblendmode:kcgblendmodenormal alpha:1.0];  // drawing code  //[mypath stroke]; } 

pragma mark - touch methods

  -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event  {   uitouch *mytouch=[[touches allobjects] objectatindex:0];  [mypath movetopoint:[mytouch locationinview:self]];   }   -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event {  uitouch *mytouch=[[touches allobjects] objectatindex:0]; [mypath addlinetopoint:[mytouch locationinview:self]]; [self setneedsdisplay];  } -(void)touchesended:(nsset *)touches withevent:(uievent *)event {    }   - (void)dealloc  {    [brushpattern release];  [super dealloc];   }   @end 

here how calling view

     signatureview=[[uiview alloc] initwithframe:cgrectmake(100,100,800,500)];  signatureview.backgroundcolor=[uicolor blackcolor];  [self.view addsubview:signatureview];      uibutton*okbutton = [uibutton buttonwithtype:uibuttontyperoundedrect];     [okbutton setframe:cgrectmake(100,420,200,40)];     [okbutton settitle:@"ok" forstate:uicontrolstatenormal];     [okbutton addtarget:self action:@selector(onokbuttonclick) forcontrolevents:uicontroleventtouchupinside];     [signatureview addsubview:okbutton];   mylinedrawingview *drawscreen=[[mylinedrawingview alloc]initwithframe:cgrectmake(10,10,700,400)];     [signatureview addsubview:drawscreen];     [drawscreen release]; 

try getting screenshot of mylinedrawingview:

- (uiimage*)takesignatureimage{   uigraphicsbeginimagecontext(drawscreen.bounds.size);       [drawscreen.layer renderincontext:uigraphicsgetcurrentcontext()];   uiimage *signatureimage = uigraphicsgetimagefromcurrentimagecontext();   uigraphicsendimagecontext();     return signatureimage; }  -(ibaction)onokbuttonclick{    uiimage *signatureimg=[self takesignatureiamge];    if(signatureimg){       yourimageview.image=signatureimg;    } } 

an make sure keep drawscreen instance variable.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -