当 webview 大于屏幕时,将 UIWebview 内容转换为 UIImage
与这个问题非常相似(还有这个答案),我正在尝试从网络视图中制作 UIImage 。到目前为止,我正在使用答案中建议的代码,具体来说:
UIGraphicsBeginImageContext(webview.bounds.size);
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
但是,当 webview 的内容大于屏幕时,生成的图像不完整并且缺少补丁。关于如何解决这个问题有什么想法吗?
Very similar to this question (and also this answer), I'm trying to make an UIImage out from a webview. So far I'm using the code suggested in the answer, specifically:
UIGraphicsBeginImageContext(webview.bounds.size);
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
However, when the contents of the webview are larger than the screen, the resulting images are not complete and have missing patches. Any ideas on how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我得到了答案:
您必须在创建图像之前将 Webview 的框架设置为完整内容大小。之后,只需将尺寸设置回原点:
I got the answer:
You have to set the frame of the Webview to the full content size just before you create the image. After this just set the size back to origin:
DR的回答很好。唯一缺少的是考虑屏幕的比例。我在我的 Swift 版本中更正了它,它对我来说工作得很好。
D R's answer is fine. The only thing missing is taking into account the scale of screen. I have it corrected in my Swift version and it works fine for me.
@Jibeex 的答案对我有用。但我必须
在下面
添加以下代码才能使其完全正常工作。写为答案是因为我没有足够的声誉来发表评论。
@Jibeex's answer worked for me. But I had to add the following code
below
for it to fully work. Writing as answer because I don't have enough reputation to comment.
我认为这会有所帮助
I think this could help
如果有人正在努力如何在 Xamarin 中执行此操作,根据 @DR 答案,以下是代码:
If someone is struggling how to do this in Xamarin, based on @DR answer, here is the code: