iOS intercept screen code

Source: Internet
Author: User

This article turns from http://blog.sina.com.cn/s/blog_801997310101a769.html

Intercept this area (Self.view):

Uigraphicsbeginimagecontext (Cgsizemake (Self.view.frame.size.width, self.view.frame.size.height));
[Self.view.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *viewimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
Uiimagewritetosavedphotosalbum (viewimage, nil, nil, nil);

Full Screen:

UIWindow *screenwindow = [[UIApplication sharedapplication] Keywindow];
Uigraphicsbeginimagecontext (screenWindow.frame.size);
[Screenwindow.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *viewimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
Uiimagewritetosavedphotosalbum (viewimage, nil, nil, nil);

The above 2 methods can be run by both the real machine and the simulator. You can see the pictures in the Photo.app.

Apple's latest Open Interface function (full screen) has already been tried and will not reject:

Cgimageref Uigetscreenimage ();
Cgimageref img = uigetscreenimage ();
uiimage* Scimage=[uiimage imagewithcgimage:img];
Uiimagewritetosavedphotosalbum (scimage, nil, nil, nil);
It still works,but only On-device (not in simulator).

Save as specified name:

UIWindow *screenwindow = [[UIApplication sharedapplication] Keywindow];

Uigraphicsbeginimagecontext (screenWindow.frame.size);
[Screenwindow.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *screenshot = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();

NSData *screenshotpng = uiimagepngrepresentation (screenshot);

Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *documentsdirectory = [Paths objectatindex:0];

Nserror *error = nil;
[Screenshotpng writetofile:[documentsdirectory stringbyappendingpathcomponent:@ "screenshot.png"] options: Nsatomicwrite error:&error];

Part of the code from: Http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app

There is no ipad real-release app can use this method to make a transparent button point, haha.

Intercept this area (Self.view):

Uigraphicsbeginimagecontext (Cgsizemake (Self.view.frame.size.width, self.view.frame.size.height));
[Self.view.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *viewimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
Uiimagewritetosavedphotosalbum (viewimage, nil, nil, nil);

Full Screen:

UIWindow *screenwindow = [[UIApplication sharedapplication] Keywindow];
Uigraphicsbeginimagecontext (screenWindow.frame.size);
[Screenwindow.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *viewimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
Uiimagewritetosavedphotosalbum (viewimage, nil, nil, nil);

The above 2 methods can be run by both the real machine and the simulator. You can see the pictures in the Photo.app.

Apple's latest Open Interface function (full screen) has already been tried and will not reject:

Cgimageref Uigetscreenimage ();
Cgimageref img = uigetscreenimage ();
uiimage* Scimage=[uiimage imagewithcgimage:img];
Uiimagewritetosavedphotosalbum (scimage, nil, nil, nil);
It still works,but only On-device (not in simulator).

Save as specified name:

UIWindow *screenwindow = [[UIApplication sharedapplication] Keywindow];

Uigraphicsbeginimagecontext (screenWindow.frame.size);
[Screenwindow.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *screenshot = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();

NSData *screenshotpng = uiimagepngrepresentation (screenshot);

Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *documentsdirectory = [Paths objectatindex:0];

Nserror *error = nil;
[Screenshotpng writetofile:[documentsdirectory stringbyappendingpathcomponent:@ "screenshot.png"] options: Nsatomicwrite error:&error];

(GO) iOS intercept screen code

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.