iOS 截屏

2019-02-27  本文已影响0人  何大叔

截取屏幕并保存本地

1. 截图

- (UIImage*)createImageWithView:(UIView*)view{

   CGSize s = view.bounds.size;

    UIGraphicsBeginImageContextWithOptions(s, YES,[UIScreen mainScreen].scale);

    [viewdrawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnimage;

}

2.保存到相册

- (void)saveImageToAlbum{

    UIImage* image = [selfcreateImageWithView:self.webView];

UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), (__bridgevoid*)self);

}

- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo

{

    if(!error){

       // NSLog(@"保存成功");

        [self.viewmakeToast:@"保存成功"];

    }else{

         [self.viewmakeToast:@"保存失败"];

         NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);

    }

}

上一篇下一篇

猜你喜欢

热点阅读