1

i m using this codes for screen capture for iOS:

CGImageRef screen = UIGetScreenImage();
UIImage *image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);  
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
CGRect screenshotFrame;  
CGImageRef screenshotRef = CGImageCreateWithImageInRect(screenshotRef, screenshotFrame);
UIImage * screenshot = [[(UIImage *)screenshotRef retain] autorelease];
CGImageRelease(screenshotRef);

But my screen contain tool bar bottom of the screen.i don't want tool bar on my captured screen. How can i crop tool bar ? How can i modified my code ?

Macmade
  • 52,708
  • 13
  • 106
  • 123
muratti
  • 11
  • 1
  • 3
  • Similar question is already marked as solved. here is link to your solution https://stackoverflow.com/questions/12687909/ios-screenshot-part-of-the-screen – Razor Jack May 11 '14 at 20:30

3 Answers3

2

I think you can capture the layer of self.view because it the root view

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    //Retina display
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
    UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Have fun!

o0oKodako0o
  • 177
  • 3
  • 9
1

Try this:

UIGraphicsBeginImageContext(/*CGRECT*/);     
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Here in CGRect pass your rect which you want to take screenshot.

Hope it helps you..

Roland Keesom
  • 8,180
  • 5
  • 45
  • 52
P.J
  • 6,547
  • 9
  • 44
  • 74
0

Set your

CGRect screenshotFrame = CGRectMake(0, 0, 320, 436);
// 480(screen height) - 44(toolbar height) = 436
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184