0

On iPhone, is there a way to tap a rounded rect button and take a screenshot, I don't want my users taking a photo by pressing sleep+home button! What are the code and frameworks needed?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Duplicate of http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically – Philipp Feb 13 '11 at 20:55

1 Answers1

3

Here's a Class method that will return a UIImage of the UIView and CGRect you pass to it:

+ (UIImage *)captureView:(UIView *)view withArea:(CGRect)screenRect {

    UIGraphicsBeginImageContext(screenRect.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextFillRect(ctx, screenRect);

    [view.layer renderInContext:ctx];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;
}
Rog
  • 18,602
  • 6
  • 76
  • 97
  • Can I add newImage to UIImage *pic = [UIImage imageNamed:@"newImage"]; in other function? And in what format is newImage? – wagashi Sep 20 '11 at 18:05