ios how to capture a particular portion of screen

后端 未结 6 1906
一生所求
一生所求 2020-12-14 11:41

I want to capture a particular portion of iPhone screen. I used UIGraphicsBeginImageContextWithOptions, but couldn\'t capture a portion of screen with this. Ple

6条回答
  •  余生分开走
    2020-12-14 12:41

    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;
    }
    

提交回复
热议问题