问题
I would like to convert html (for example, a table) to an image and save it as a .jpg file. And, if that table is displayed within a web page along with other elements, I only want to get that specific table and save it as an image.
Is this possible using asp.net?
thanks
回答1:
I think this is a rendering issue and completely depends upon what browser rendering your HTML.
But this the closest thing I could get you using GDI+
and WebBrowser
control from CodeProject.
Let me know whether it helped you or not!
Regards.
回答2:
We have used http://iecapt.sourceforge.net/
to convert HTML to image. You can try it out. It is available for FREE.
or
ref
http://stackoverflow.com/questions/1972739/convert-a-html-control-div-or-table-to-an-image-using-c
回答3:
<%@ Page Language="c#"%>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e) {
Bitmap bmp= new Bitmap(Server.MapPath(Request.QueryString["i"]));
Graphics g=Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias ;
g.DrawString(Request.QueryString["t"],
new Font("verdana",12),SystemBrushes.WindowText, 1, 1);
Response.ContentType="image/jpeg";
bmp.Save(Response.OutputStream, bmp.RawFormat) ; }
</script>
来源:https://stackoverflow.com/questions/3165318/how-to-convert-block-of-html-to-an-image-e-g-jpg-in-asp-net