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]