将 ASP.NET MVC ViewResult HTML 渲染为图像,无需第三方组件
有没有办法将 ViewResult 或 PartialViewResult 渲染为图像?
我尝试将 ViewResult 作为字符串获取,并且得到了一个包含 html 的字符串,但我需要将该 html 渲染为图像。如果可能的话 - 带样式和图像。
我有一个想法,在服务器上获取此 html 的一些浏览器输出并将结果捕获到图像中,但目前我不知道在实践中如何实现。 如果您有任何想法,请帮忙。
请不要建议任何第三方组件。只需判断标准 .NET 类是否无法做到这一点即可。
谢谢
is there a way to render ViewResult or PartialViewResult as an image?
I have tried to get ViewResult as string and I got a string containing html as it should be, but I need to render that html to image. If it is possible - with styles and images.
I have an idea to get some browser output for this html on server and capture result to an image, but how it can be done in practice I don't know at this time.
If you have any ideas, please, help.
Please do not suggest any third party components. Just tell if it is impossible to do by standart .NET classes.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅如何使用 WebBrowser 控件呈现图像
然后就很简单了
See How to render an image using the WebBrowser control
Then it's as easy as
抱歉我之前的建议。这确实是不正确的。现在我明白你想要什么了。但是,如果您不喜欢使用第三方解决方案的想法,唯一的方法就是编写自己的解析器,这并不是一件容易的事。或者您可以尝试使用 WebBrowser 类及其方法 DrawToBitmap ,其描述如下 http://englestone.blogspot.com/2009/06/generate-screenshot-previews-with-c.html
Sorry for my previous suggestion. It was not correct, really. Now I understand what you want. But if you don't like the idea to use the third-party solutions the only way is to write your own parser and it's not easy task. Or you could try to use WebBrowser class and its method DrawToBitmap how it's described here http://englestone.blogspot.com/2009/06/generate-screenshot-previews-with-c.html