当客户端用户单击按钮时,我尝试获取客户端用户的屏幕截图。
该代码在本地计算机上有效。但是,当我在服务器上发布时,该代码无效。我收到“句柄无效”错误。
我的错误在哪里?
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();
}
您不能使用Screens
该类,因为ASP.NET不在桌面交互模式下运行。您无法从用户或服务器从ASP.NET中的代码访问屏幕。
您应恢复为最佳,以客户端的JavaScript来得到当前网页的屏幕截图。那是你所能做的最好的。(请不要参加ActiveX导览)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句