Capture the entire view:
-(uiimage*) Captureview: (UIView *) theview{ = theview.frame; if class ]]) { = ((Uiscrollview *) theview). contentsize; } Uigraphicsbeginimagecontext (rect.size); = Uigraphicsgetcurrentcontext (); [Theview.layer Renderincontext:context]; *img = uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); return img;}
To intercept a part of a view:
-(UIImage *) Cropimage: (UIImage *=*img = [UIImage imagewithcgimage:imageref]; return img;}
Intercept Scrollerview:
-(UIImage *) Capturescrollview: (Uiscrollview *) scrollview{UIImage* Image =Nil; Uigraphicsbeginimagecontext (scrollview.contentsize); {Cgpoint Savedcontentoffset=Scrollview.contentoffset; CGRect Savedframe=Scrollview.frame; Scrollview.contentoffset=Cgpointzero; Scrollview.frame= CGRectMake (0,0, ScrollView.contentSize.width, scrollView.contentSize.height); [Scrollview.layer Renderincontext:uigraphicsgetcurrentcontext ()]; Image=Uigraphicsgetimagefromcurrentimagecontext (); Scrollview.contentoffset=Savedcontentoffset; Scrollview.frame=Savedframe; } uigraphicsendimagecontext (); if(Image! =Nil) { returnimage; } returnNil;}
Stitching of multiple images:
-(UIImage *) Composewithheader: (UIImage *) header content: (UIImage *) content footer: (UIImage *) footer{cgsize size= Cgsizemake (Content.size.width, header.size.height +content.size.height +footer.size.height); Uigraphicsbeginimagecontext (size); [Header Drawinrect:cgrectmake (0, 0, Header.size.width, Header.size.height)]; [Content Drawinrect:cgrectmake (0, Header.size.height, Content.size.width, Content.size.height)]; [Footer Drawinrect:cgrectmake (0, Header.size.height+content.size.height, Footer.size.width, Footer.size. Height)]; UIImage*image =Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); returnimage;}
iOS image capture function image stitching function