1

i am using this code to capture my screen.

        CGImageRef screen = UIGetScreenImage();
    UIImage* image = [UIImage imageWithCGImage:screen];
    CGImageRelease(screen);
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

this code take all of the screen. i need only some of it... CGRect rect = CGRectMake (0,0,100,100);

can i pass any parameter to get it?

thanks!

OAZ
  • 121
  • 1
  • 11

3 Answers3

4

you can also define a new context for the rect size you want :

CGRect rect = CGRectMake (0,0,100,100);
UIGraphicsBeginImageContext(rect);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshot, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

Nota : you need to add QuartzCore in import :

#import <QuartzCore/QuartzCore.h>

and you can get main view with :

UIView *view = [[UIApplication sharedApplication].keyWindow rootViewController].view
Diwann
  • 888
  • 1
  • 8
  • 28
1

Sounds like you simply want or need to crop your UIImage.

Check out the code in this related question and see if it helps you out:

How to crop the UIImage?

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
1

Use this code to capture screen and automatically saved to Image library in iphone device.

 UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
Ravi Kumar Karunanithi
  • 2,151
  • 2
  • 19
  • 41