且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以使用ASP.NET MVC将视图(HTML)转换为图像?

更新时间:2023-02-15 22:02:26

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



为什么你如此反对第三方工具?例如, HTML-Renderer [ ^ ]看起来它可以完全满足您的需求,并且可以免费使用。 许可证 [ ^ ]看起来也很轻松。
The only built-in option would be to use the WebBrowser control in a new thread, as described in this *** 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);
}