2

I've seen a lot of questions and answers about screenshot, I know how to do it, this is not my problem, this is my code:

- (void)takeScreenShot
{
    //UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 340), YES, 0.);
    UIGraphicsBeginImageContext(CGSizeMake(320, 480));
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

How is it possible to take a round screen shot instead of just 320x480 square frame?

ytpm
  • 4,962
  • 6
  • 56
  • 113

2 Answers2

3

You could try this:

- (UIImage *)takeRoundedScreenShot:(CGPoint)center
{
  float cornerRadius = self.view.window.layer.cornerRadius;
  CGAffineTransform savedTransform = self.view.window.transform;

  UIGraphicsBeginImageContext(CGSizeMake(320, 320));
  self.view.window.layer.cornerRadius = 160;
  self.view.window.clipsToBounds = YES;
  self.view.window.transform = CGAffineTransformMakeTranslation(-(center.x-160), -(center.y-160));
  [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  self.view.window.transform = savedTransform;
  self.view.window.layer.cornerRadius = cornerRadius.

  return viewImage;
}
sergio
  • 68,819
  • 11
  • 102
  • 123
  • 3
    You should restore the view state after taking the screenshot :P – Lefteris Oct 22 '12 at 08:43
  • Thanks for the comment, but I keep gettings this error: "Assigning to 'CGAffineTransform' (aka 'struct CGAffineTransform') from incopatible type 'int'" from this line: " self.view.window.transform = CGAffineTransformTranslateMake(-(center.x-160), -(center.y-160));" – ytpm Oct 22 '12 at 08:59
1

I don’t think it’s possible, but you can always round the corners yourself?

Community
  • 1
  • 1
zoul
  • 102,279
  • 44
  • 260
  • 354