ios-screenshots and encapsulate the screenshot as a method

Source: Internet
Author: User

////Uiimage+tools.h//Screen Cutting////Created by Yaguangzhu on 15/9/10.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<UIKit/UIKit.h>@interfaceUIImage (Tools)+ (Instancetype) Imagewithcaptureview: (UIView *) view;@end////UIIMAGE+TOOLS.M//Screen Cutting////Created by Yaguangzhu on 15/9/10.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "Uiimage+tools.h"@implementationUIImage (Tools)+ (Instancetype) Imagewithcaptureview: (UIView *) view{uigraphicsbeginimagecontextwithoptions (view.bounds.size, NO,0.0); Cgcontextref CTX=Uigraphicsgetcurrentcontext ();        [View.layer Renderincontext:ctx]; UIImage*newimage =Uigraphicsgetimagefromcurrentimagecontext ();        Uigraphicsendimagecontext (); returnnewimage;}@end
////VIEWCONTROLLER.M//Screen Cutting////Created by Yaguangzhu on 15/9/10.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"#import "Uiimage+tools.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.UIImage *newimage =[UIImage ImageWithCaptureView:self.view]; NSData*data =uiimagepngrepresentation (newimage); [Data writetofile:@"/users/yaguangzhu/desktop/00d1.png"Atomically:yes]; }- (void) captureview{uigraphicsbeginimagecontextwithoptions (self.view.bounds.size, NO,0.0); Cgcontextref CTX=Uigraphicsgetcurrentcontext ();        [Self.view.layer Renderincontext:ctx]; UIImage*newimage =Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext (); NSData*data =uiimagepngrepresentation (newimage); [Data writetofile:@"/users/yaguangzhu/desktop/00d1.png"Atomically:yes];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

Ios-and wrapping as a method

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.