Usage scenarios:
Code generation snippet in IOS 7
Using context and clipping with the specified area, template code-(void) screenshot{ //Will be view, that is, view of the form's root controller (must not contain status bar, default iOS7 controller is included in the status bar) Beyondviewcontroller *BEYONDVC = Self.view.window.rootViewController; The total size of the background picture is cgsize size = beyondVC.view.frame.size; Open context, after using the parameters, the original image (yes 0.0 high quality) uigraphicsbeginimagecontextwithoptions (size, yes, 0.0) is truncated; The clipping of the key code, the rectangular range to be clipped cgrect rect = CGRectMake (0, -20, size.width, Size.Height +); Note: IOS7 after Renderincontext: by drawviewhierarchyinrect:afterscreenupdates: substitution [Beyondvc.view Drawviewhierarchyinrect:rect Afterscreenupdates:no]; From the context, remove UIImage UIImage *snapshot = Uigraphicsgetimagefromcurrentimagecontext (); Add the captured image to the image array [_cutimages addobject:snapshot]; Remember, end context (remove stack top) uigraphicsendimagecontext (); }
Code Snippets in IOS 6
Using context, template code-(void) screenshot3{ //Will be view, form's root controller view (IOS6, default controller does not contain status bar) Beyondviewcontroller *BEYONDVC = Self.view.window.rootViewController; UIView *cutview = Beyondvc.view; Open context, after using the number of references, the original (yes 0.0 high quality) uigraphicsbeginimagecontextwithoptions (cutView.frame.size, yes, 0.0); Render the Cutview layer into context [Cutview.layer renderincontext:uigraphicsgetcurrentcontext ()]; Remove UIImage UIImage *image = Uigraphicsgetimagefromcurrentimagecontext (); Add the captured image to the image array [_cutimages addobject:image]; Remember, end context uigraphicsendimagecontext ();}
Ios_ screenshot and Crop