日期:2014-05-19  浏览次数:20450 次

请问如何为网页生成图片
获取其它网站页面到当前主机的内存中,将这个网页在内存中生成图片并存为文件,现在我遇到一个难题,就是怎样把抓取的网页生成为图片,哪位高手能给个思路或者代码,不胜感激.

------解决方案--------------------
codeproject
htmltoimage
------解决方案--------------------
百度上的

今天在 http://dotnetjunkies.com/WebLog/alan.dean/archive/2005/04/25/70496.aspx 看到了另外一种方法:通过IE截图
private void OnDocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
using (Graphics srcGraphics = this.axWebBrowser1.CreateGraphics())
{
using (Graphics destGraphics = this.pictureBox1.CreateGraphics())
{
IntPtr hdcDest = destGraphics.GetHdc();
IntPtr hdcSrc = srcGraphics.GetHdc();
GDI32.BitBlt(
hdcDest,
0, 0,
this.axWebBrowser1.ClientRectangle.Width, this.axWebBrowser1.ClientRectangle.Height,
hdcSrc,
0, 0,
(int) GDI32.TernaryRasterOperations.SRCCOPY
);
srcGraphics.ReleaseHdc(hdcSrc);
destGraphics.ReleaseHdc(hdcDest);
}
}
}


------解决方案--------------------
晕,点空格居然自动提交了
重新写
//生成图片的网页有如下代码
//生成图片的代码
/* 省略 */
//将图片写入Response
System.IO.MemoryStream ms = new System.IO.MemoryStream();
//将开始生成的图片保存
newBitmap.Save(ms, ImageFormat.Jpeg);
//输出图片
Response.ClearContent();
Response.ContentType = "image/gif ";
Response.BinaryWrite(ms.ToArray());
//比如这个网页名字是1.aspx
则其他页面调用他时将url属性设为~/1.aspx就可以了