iOS Screenshot part of the screen

Well the screenshot is taken from a canvas you draw.
So instead of drawing your layer in the whole context, with a reference to top left corner, you will draw it where you want to take the screenshot….

//first we will make an UIImage from your view
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *sourceImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//now we will position the image, X/Y away from top left corner to get the portion we want
UIGraphicsBeginImageContext(sshot.frame.size);
[sourceImage drawAtPoint:CGPointMake(-50, -100)];
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(croppedImage,nil, nil, nil);

Leave a Comment