解决方案 »
- c#怎么定义全局变量?
- 怎么规定RichTextBox控件中RTF的样式?
- Server.URLEncode的问题
- 小白想初步实现计算器的加减乘除功能。。。有图片。希望高手指点。
- =====菜鸟问题,请高手解答,WinForm文件操作问题=======
- 又是窗体传值啊,知道的高手们进来看下啊,困扰我好久了,进度就此打住了
- 诡异的问题,哪位能给出标准答案?一百分送上
- DataGirdView
- 'document.getElementById(...)'为空或不是对象 请求帮助!
- WINDOWS服务启动应用程序看不到界面
- C# OutLook 插件 怎么压缩PST文件
- 怎么在一个string类型变量后面加上一个char类型呢?
另外保存快照,现在应该都是html吧简单的,
你可以把用webform调用winform运行,生成快照
“把用webform调用winform运行,生成快照”,能给个例子吗?
谢谢!
主要用到了WebBrowser.DrawToBitmap方法(继承自WebBrowserBase)。public void DrawToBitmap (
Bitmap bitmap,
Rectangle targetBounds
)WebForm要想用WebBrowser类,估计要添加引用“System.Windows.Forms”。在项目上点右键-“添加引用”-找到对应你网站.net框架版本的System.Windows.Forms并添加,就有System.Windows.Forms.WebBrowser了
我把整个页面(1.aspx)代码都贴出来,能帮我直接修改吗?
先谢了!<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<%
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
/// <summary>
/// 生成网页快照
/// </summary>
publicclassHtmlToImg
{
Bitmap m_Bitmap;
string m_Url;
int m_BrowserWidth, m_BrowserHeight, m_ThumbnailWidth, m_ThumbnailHeight; //这里出现错误信息:“编译器错误信息: CS1513: 应输入 }”
public HtmlToImg(string Url, int BrowserWidth, int BrowserHeight, int ThumbnailWidth, int ThumbnailHeight)
{
m_Url = Url;
m_BrowserHeight = BrowserHeight;
m_BrowserWidth = BrowserWidth;
m_ThumbnailWidth = ThumbnailWidth;
m_ThumbnailHeight = ThumbnailHeight;
}
publicstaticBitmap GetHtmlToImg(string Url, int BrowserWidth, int BrowserHeight, int ThumbnailWidth, int ThumbnailHeight)
{
HtmlToImg thumbnailGenerator = newHtmlToImg(Url, BrowserWidth, BrowserHeight, ThumbnailWidth, ThumbnailHeight);
return thumbnailGenerator.GenerateHtmlToImgImage();
}
publicBitmap GenerateHtmlToImgImage()
{
Thread m_thread = newThread(newThreadStart(_GenerateHtmlToImgImage));
m_thread.SetApartmentState(ApartmentState.STA);
m_thread.Start();
m_thread.Join();
return m_Bitmap;
}
privatevoid _GenerateHtmlToImgImage()
{
WebBrowser m_WebBrowser = newWebBrowser();
m_WebBrowser.ScrollBarsEnabled = false;
m_WebBrowser.Navigate(m_Url);
m_WebBrowser.DocumentCompleted += newWebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
while (m_WebBrowser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
m_WebBrowser.Dispose();
}
privatevoid WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser m_WebBrowser = (WebBrowser)sender;
m_WebBrowser.ClientSize = newSize(this.m_BrowserWidth, this.m_BrowserHeight);
m_WebBrowser.ScrollBarsEnabled = false;
m_Bitmap = newBitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height);
m_WebBrowser.BringToFront();
m_WebBrowser.DrawToBitmap(m_Bitmap, m_WebBrowser.Bounds);
m_Bitmap = (Bitmap)m_Bitmap.GetThumbnailImage(m_ThumbnailWidth, m_ThumbnailHeight, null, IntPtr.Zero);
}
}//调用方法: Bitmap bmp = HtmlToImg.GetHtmlToImg("http://www.baidu.com/", 800, 600, 800, 600);
MemoryStream stream = newMemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] buff = stream.ToArray();
//直接显示图片
//Response.ContentType = "image/Jpeg";
//Response.BinaryWrite(buff);
//Response.End(); //保存图片
FileStream fs = newFileStream(Server.MapPath(DateTime.Now.Date.ToShortDateString() + ".jpg"), FileMode.Create);
stream.WriteTo(fs);
stream.Close();
fs.Close();
%>
</body>
</html>
public class HtmlToImgHtmlToImg这是一个单独的类。。
调用方法那段代码你应该放到一个事件处理程序中,比如按钮的点击事件。不然你放到page_load事件里也行,页面一打开就执行了。
最高只能加到100分了,谢谢!