2

我看过很多关于截图的问题和答案,我知道该怎么做,这不是我的问题,这是我的代码:

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

怎么可能拍摄一个圆形屏幕而不是 320x480 方框?

4

2 回答 2

3

你可以试试这个:

- (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;
}
于 2012-10-22T08:41:34.947 回答
1

我不认为这是可能的,但你总是可以自己绕过角落吗?

于 2012-10-22T08:31:01.613 回答