是否可以使用ASP.NET MVC将视图(HTML)转换为图像? [英] Is it possible to covert a view (HTML) into an image using ASP.NET MVC?

查看:140
本文介绍了是否可以使用ASP.NET MVC将视图(HTML)转换为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我想要转换包含HTML&要映像的CSS元素,然后将其传递给用户。我只是想知道C#中是否有内置库可以动态生成图像?

请不要建议我使用第三方工具。



我尝试了什么:



我迷路了,我不知道从哪里开始。

I have a requirement where I want to convert a whole view which contains HTML & CSS elements to image and then pass it to the users. I am just wondering is there any builtin library in C# to generate images out of a view on the fly?
Please do not suggest me third party tools.

What I have tried:

I am lost and I don't know where to start from.

推荐答案

唯一的内置选项是在新线程中使用 WebBrowser 控件,如这个StackOverflow答案 [ ^ ]。 然而,这可能不会在ASP.NET站点中很好地工作。



为什么你如此反对第三方工具?例如, HTML-Renderer [ ^ ]看起来它可以完全满足您的需求,并且可以免费使用。 许可证 [ ^ ]看起来也很轻松。
The only built-in option would be to use the WebBrowser control in a new thread, as described in this StackOverflow answer[^]. However, that's probably not going to work very well in an ASP.NET site.

Why are you so opposed to third-party tools? For example, HTML-Renderer[^] looks like it would do exactly what you need, and is free to use. The license[^] looks pretty relaxed too.


你可以只进行一次屏幕截图相应调整图像大小?我在Google上找到了这个解决方案,几乎没有搜索。



You could just take a screen capture and adjust the image size accordingly? I found this solution on Google with little searching.

Rectangle bounds = Screen.GetBounds(Point.Empty);
using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using(Graphics g = Graphics.FromImage(bitmap))
    {
         g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }
    bitmap.Save("test.jpg", ImageFormat.Jpeg);
}


这篇关于是否可以使用ASP.NET MVC将视图(HTML)转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆