ios how to capture a particular portion of screen

Bai picture Bai · Oct 27, 2011 · Viewed 11.7k times · Source

I want to capture a particular portion of iPhone screen. I used UIGraphicsBeginImageContextWithOptions, but couldn't capture a portion of screen with this. Please help me.

Answer

Superdev picture Superdev · Mar 5, 2012

you can use this code

UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGRect rect = CGRectMake(250,61 ,410, 255);
CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], rect);

UIImage *img = [UIImage imageWithCGImage:imageRef]; 

UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil); 

CGImageRelease(imageRef);