how to take a screenshot of the iPhone programmatically?

前端 未结 11 1840
谎友^
谎友^ 2020-11-28 08:01

Is it possible in objective C that we can take the screen shot of screen and stored this image in UIImage.

11条回答
  •  春和景丽
    2020-11-28 08:12

    try this...

    - (UIImage*)captureView:(UIView *)view 
    {
        CGRect rect = [[UIScreen mainScreen] bounds];
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [view.layer renderInContext:context];
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    }
    
    - (void)saveScreenshotToPhotosAlbum:(UIView *)view 
    {
        UIImageWriteToSavedPhotosAlbum([self captureView:self.view], nil, nil,nil);
    }
    

提交回复
热议问题