C# asp.net中的Div屏幕截图
我想在asp.net中拍摄一个Div元素的屏幕截图,并将其保存到磁盘。我不想使用html2canvas库或html5画布元素。方法可以是服务器端或客户端。未经测试,但发现:C# asp.net中的Div屏幕截图,c#,javascript,asp.net,html,screenshot,C#,Javascript,Asp.net,Html,Screenshot,我想在asp.net中拍摄一个Div元素的屏幕截图,并将其保存到磁盘。我不想使用html2canvas库或html5画布元素。方法可以是服务器端或客户端。未经测试,但发现: public Bitmap GenerateScreenshot(string url, int width, int height) { // Load the webpage into a WebBrowser control WebBrowser wb = new WebBrowser(); w
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
未经测试,但发现:
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
您在该div中持有什么?div包含一些文本和图像…要求访问者拍摄屏幕截图并上传它将不符合您的要求:-P(只是为了安全起见)让我举一个例子……考虑OmEGLE……看看这个链接……你可以看到聊天被转换成一个图像……我想做的同样的事情……你在DIV中持有什么?DIV包含一些文本和图像……问访问者拿截图和上传它将不能满足你的要求吗?P(为了安全起见)让我举一个例子……考虑OmEGLE……看看这个链接……你可以看到聊天被转换成一个图像……我想做同样的事情……我已经通过了这个代码……它是一个基于Windows窗体的函数,因为WebBuffor类出现在Sytor.WINDOWS.Form命名空间……并且在ASP.NET中使用Windows窗体将是一个坏消息。想法…无论如何,感谢您的回复…欢迎更多建议:)…我仍然不明白为什么omegle会做同样的事情…就像这个链接一样,您几乎肯定需要第三方。似乎是最好的支持。只需要一个exe。有一些线程注意事项,但加载WebBrowser控件在asp.net中工作正常。我自己也用过类似的东西。我会研究这件事……欢迎更多的想法……有人知道omegle Div捕获技术吗?我已经看过这段代码了……这是一个基于windows窗体的函数,因为system.windows.forms命名空间中存在webbrowser类……在asp.net中使用windows窗体将是一个糟糕的选择想法…无论如何,感谢您的回复…欢迎更多建议:)…我仍然不明白为什么omegle会做同样的事情…就像这个链接一样,您几乎肯定需要第三方。似乎是最好的支持。只需要一个exe。有一些线程注意事项,但加载WebBrowser控件在asp.net中工作正常。我自己也用过类似的东西。我会研究这个东西……欢迎更多的想法……有人知道omegle Div捕获技术吗?