我试过这段代码,但显示错误 [英] i tried this code but shows error

查看:68
本文介绍了我试过这段代码,但显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以屏幕截图捕捉网页并将屏幕截图保存在文件夹中。



捕获图像代码如下



I am capturing the webpage as screen shot and save the screen shot in folder.

Capture image code as follows

protected void btnCapture_Click(object sender, EventArgs e)
 {

 Bitmap bitmap = new Bitmap
 (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);

Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

bitmap.Save(Server.MapPath(@"File\ScreenShot.bmp"), ImageFormat.Bmp);

}







但是当我运行上面的代码时显示错误为关注






But when i run the above code shows error as follows

A generic error occurred in GDI+.





请帮助我上面的代码中有什么问题。



please kindly help me what is the problem in my above code.

推荐答案

这里有两件事,你得到的错误并不大一个!

最大的问题是

该代码不会捕获网页,除了在您的开发机器上 - C#代码在服务器上运行,而不是客户端,并且无法访问客户端显示。

仅在开发计算机上工作,因为客户端和服务器是同一台计算机。



您注意到的问题可能是Server.MapPath尝试使用不存在的文件夹(路径相对于当前页面,您可能需要:
There are two things here, and the error you get is not the big one!
The big problem is
That that code isn't going to capture the webpage, except on your development machine - C# code runs on the server, not the client, and has no access to the client display.
It "works" on the development machine only because the client and server are the same computer.

The problem you have noticed is probably the Server.MapPath trying to work with a folder that isn't there (the path is relative to the current page , and you probably want:
bitmap.Save(Server.MapPath(@"~\File\ScreenShot.bmp"), ImageFormat.Bmp);



或文件夹没有设置适当的访问权限,以便该文件夹对运行IIS代码的用户没有写入权限。


Or the folder does not have the appropriate access permissions set so the folder does not have write permission for the user running the IIS code.


这篇关于我试过这段代码,但显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆