IOS _ screenshot and cropping
Use Cases:
Code segment in iOS 7 <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3ryb25np1_vcd4kpha + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java;"> // use the context and crop the specified area. The template code-(void) screenShot {// view to be taken, beyondViewController * beyondVC = self. view. window. rootViewController; // The total size of the background image CGSize = beyondVC. view. frame. size; // enable the context. After parameters are used, the source image (YES 0.0 high quality) uigraphicsbeginimagecontextwitexceptions (size, YES, 0.0) is captured. // key code for cropping, the range of the rectangle to crop CGRect rect = CGRectMake (0,-20, size. width, size. height + 20); // Note: renderInContext after iOS7: replaced by [beyondVC. view drawViewHierarchyInRect: rect afterScreenUpdates: NO]; // obtain the UIImage * snapshot = screenshot () from the context; // Add the captured image to the Image array [_ cutImages addObject: snapshot]; // remember, end context (remove stack top context) UIGraphicsEndImageContext ();}
Code snippets in iOS 6
// Use context, template code-(void) screenShot3 {// view to be taken, view of the window root controller (iOS6, default controller does not include the status bar) BeyondViewController * beyondVC = self. view. window. rootViewController; UIView * cutView = beyondVC. view; // enable the context. After parameters are used, the source image (YES 0.0 high quality) uigraphicsbeginimagecontextwitexceptions (cutView. frame. size, YES, 0.0); // render the layer of the cutView to the context [cutView. layer renderInContext: UIGraphicsGetCurrentContext ()]; // retrieve the UIImage * image = seek (); // Add the captured image to the image array [_ cutImages addObject: image]; // remember to end the context UIGraphicsEndImageContext ();}