【发布时间】:2015-02-10 13:11:40
【问题描述】:
当客户端用户单击按钮时,我尝试获取客户端用户的屏幕截图。
此代码在本地机器上运行。但是当我在服务器上发布时它不起作用。我收到“句柄无效”错误。
我的错误在哪里?
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing;
public partial class Page: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {...}
}
static string ImagePath;
public static void ScreenShot()
{
foreach (Screen screen in Screen.AllScreens)
{
Bitmap bitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(screen.Bounds.X, screen.Bounds.Y, 0, 0, screen.Bounds.Size, CopyPixelOperation.SourceCopy);
}
ImagePath= "/Screenshots/" + HttpContext.Current.Session["UserName"].ToString()+ " "+ DateTime.Now.ToString("dd.MM.yyyy HH.mm.ss");
bitmap.Save(HttpContext.Current.Server.MapPath(ImagePath+ ".jpg"));
}
}
protected void btn_Click(object sender, EventArgs e)
{
ScreenShot();
}
【问题讨论】: