objective-c - 如何拍摄圆形屏幕截图?
<p><p>我看过很多关于截图的问题和答案,我知道该怎么做,这不是我的问题,这是我的代码:</p>
<pre><code>- (void)takeScreenShot
{
//UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 340), YES, 0.);
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
;
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
</code></pre>
<p>如何拍摄圆形屏幕而不是 320x480 方框?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以试试这个:</p>
<pre><code>- (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));
;
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.window.transform = savedTransform;
self.view.window.layer.cornerRadius = cornerRadius.
return viewImage;
}
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - 如何拍摄圆形屏幕截图?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13007512/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13007512/
</a>
</p>
页:
[1]