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

问题描述

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



捕获图像代码如下



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.

推荐答案

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.


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

08-23 04:45