IOS _ screenshot and cropping

Source: Internet
Author: User

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 ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.