Take snapshot of view / WebView programmatically

南楼画角 提交于 2019-12-18 13:48:19

问题


I want to take a snapshot of a view (WebView) or, if that is not possible, the whole screen, so I can save it into the user's photo gallery. I was wondering if this is possible.


回答1:


To get the image, you'll want to use:

UIGraphicsBeginImageContext(self.bounds.size);

[theView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

Then, to save to the Photos Library:

UIImageWriteToSavedPhotosAlbum(viewImage,nil,NULL,NULL);


来源:https://stackoverflow.com/questions/501496/take-snapshot-of-view-webview-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!