iOS screenshot code [go]

Source: Internet
Author: User

Http://www.cnblogs.com/chenxiangxi/p/3547974.html

The blogger's connection writes the screenshot code for the iOS custom size location very well, and it's a good way to do it right away for programmers who just want to use it right away.

Http://www.2cto.com/kf/201310/250228.html

I changed it to the following code:

 1 #pragma mark-===== logic code =====-2 static int screenshotindex=0 for custom screenshot position size; The logic here directly uses the above blogger's Logic 3-(void) screenshot{4//here because I need full-screen connection, so directly changed, macro definition IPADWITHD for 1024,ipadheight for 768, 5//Uigraphicsbeg     Inimagecontextwithoptions (Cgsizemake (640, 960), YES, 0);     Set screenshot size 6 uigraphicsbeginimagecontextwithoptions (Cgsizemake (Ipadwidth, Ipadheight), YES, 0); Set screenshot size 7 [[Self.view layer] renderincontext:uigraphicsgetcurrentcontext ()]; 8 UIImage *viewimage = Uigraphicsgetimagefromcurrentimagecontext (); 9 Uigraphicsendimagecontext (); Cgimageref imageref = viewimage.cgimage;11//CGRect rect = CGRectMake (166, 21 1, 426, 320);//Here you can set the desired area of the cgrect rect = CGRectMake (0, 0, ipadwidth, ipadheight);//Here you can set the desired area. Cgimageref imag Erefrect =cgimagecreatewithimageinrect (Imageref, rect); UIImage *sendimage = [[UIImage alloc] Initwithcgimage:imager Efrect];15 Uiimagewritetosavedphotosalbum (sendimage, nil, nil, nil);//save pictures to photo gallery NSData *imageviewdata = UIImagePngrepresentation (sendimage); Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, NSUse Rdomainmask, YES); NSString *documentsdirectory = [Paths objectatindex:0];20 nsstring *picturename= [NSString St ringwithformat:@ "Screenshow_%d.png", screenshotindex];21 nsstring *savedimagepath = [documentsDirectory Stringbyappendingpathcomponent:picturename];22 NSLog (@ "screenshot path printing:%@", Savedimagepath); 23//Here I set the path to a global string, which does not Well, I'm just trying to use it, I hope you don't write it this way [self setpickpath:savedimagepath];25] [imageviewdata writetofile:savedimagepath Atomicall y:yes];//save photos to sandbox directory cgimagerelease (imagerefrect); screenshotindex++;29}30//set path to-(void) Setpickpath: (Nsstri ng *) pickimage {_screenshotspickpath = pickimage;33}34//Get path < Here I go directly to the code of the mail push, can achieve the effect, but there must be a better way of writing >35-(nsstr ing *) getpickpath {_screenshotspickpath;37}

iOS screenshot code [go]

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.