简体   繁体   English

是否可以使用带有C#代码的ASP.net截取网页的屏幕截图

[英]Is it possible to take a screenshot of a web page with ASP.net with C# Code

Is it possible to take a screenshot of a web page with ASP.net with C# Code and then submit that back to the server? 是否可以使用带有C#代码的ASP.net截取网页截图,然后将其提交回服务器? In this code access only local host only, but same source code not access to the IIS, CopyFromScreen error ware occurred. 在此代码中仅访问本地主机,但相同的源代码无法访问IIS,发生CopyFromScreen错误。 What is the reason is it possible? 可能的原因是什么?

Sample Source Code: 示例源代码:

Bitmap Bitmap;
Graphics Graps;
Bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height - 110, PixelFormat.Format32bppArgb);
Graps = Graphics.FromImage(Bitmap);
Graps.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, 110, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
Bitmap.Save(Server.MapPath("~") + "/YourShot.gif");

Using a bitmap (even a JPG) strikes me as a very expensive way to store the web page and also one that you wouldn't be able to easily parse or compare with different versions (eg on different dates). 使用位图(甚至是JPG)让我觉得这是一种非常昂贵的存储网页的方式,也是一种你无法轻易解析或与不同版本进行比较的方法(例如在不同的日期)。 If you'd like to explore the alternative - pulling the web site HTML down to the server, just do this: 如果您想探索替代方案 - 将网站HTML下拉到服务器,只需执行以下操作:

WebRequest wrContent = WebRequest.Create("http://www.destsite.com/yourpage.aspx");
Stream objStream = wrContent.GetResponse().GetResponseStream();
StreamReader objStreamReader = new StreamReader(objStream);
string pageContent = objStreamReader.ReadToEnd();

Hope this helps...something to think about, anyway. 无论如何,希望这有助于......思考一些事情。

I am little confused. 我有点困惑。 You are taking the screenshot of the server and saving it there? 您正在截取服务器的屏幕截图并将其保存在那里? Whats the point in it? 它的重点是什么?

What exactly are tring to do here? 到底要做什么? If you want to take the screen shot of a web page then you might want to look at this question . 如果您想拍摄网页的屏幕截图,那么您可能想看看这个问题

We have another question here : How do you take a Screenshot of a website via .Net code? 我们在这里有另一个问题: 你如何通过.Net代码获取网站的屏幕截图?

ere is another question about taking screenshot 关于截屏的另一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM