且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ios如何捕获屏幕的特定部分

更新时间:2023-01-15 18:01:52

您可以使用 UIGraphicsGetImageFromCurrentContext $ c进行截屏$ C>。从内存中写下面的代码,因此可能出错。请自行更正。

You can take screen shot using UIGraphicsGetImageFromCurrentContext. Wrote below code from memory, so errors possible. Please correct it yourself.

- (UIImage*)captureView:(UIView *)yourView {
    CGRect rect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [yourView.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}