【问题标题】:Taking screenshot not working in window service c#截屏在窗口服务c#中不起作用
【发布时间】:2014-01-26 01:31:02
【问题描述】:

我正在使用捕获屏幕并将图像阵列上传到服务器。但是在截屏时会出现win32异常,我的代码如下:

            private static Bitmap bmpScreenshot;
            private static Graphics gfxScreenshot;
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height ,PixelFormat.Format32bppArgb);

            gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bmpScreenshot.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] bmpBytes = ms.GetBuffer();
            bmpScreenshot.Dispose();
            ms.Close();

具体错误如下:服务无法启动。 System.ComponentModel.Win32Exception (0x80004005):句柄无效 在 System.Drawing.Graphics.CopyFromScreen(Int32 sourceX,Int32 sourceY,Int32 destinationX,Int32 destinationY,大小块区域大小,CopyPixelOperation copyPixelOperation) 在 F:\Umesh Projects\ScreenShare\ScreenShare\ScreenShare\ScreenShare.cs:line 48 中的 ScrrenShare.ScreenShare.TraceService() 在 F:\Umesh Projects\ScreenShare\ScreenShare\ScreenShare\ScreenShare.cs:line 29 中的 ScrrenShare.ScreenShare.OnStart(String[] args) 在 System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(对象状态) 请让我知道解决方案。代码在 Window 窗体应用程序中工作正常谢谢 adv。

【问题讨论】:

  • 具体错误是什么?
  • 问题已更新为特定错误。感谢您回复我...代码在窗口窗体应用程序中运行良好...

标签: c# web-services screenshot


【解决方案1】:

你做了这一步吗?

在管理工具中设置服务的属性->服务->右键单击您的服务->转到属性->在登录选项卡下检查允许与桌面交互。

【讨论】:

  • 它解决了 Win32 异常问题。但它保存为空白屏幕。它没有捕获原始图像。只是显示空白图像。让我知道任何想法。
  • 您是否在与活动用户相同的登录名下运行它?
  • 是的,我在与活动用户相同的用户中运行...!
  • 没有解决问题。只有在用户实际登录时才能截屏。
  • 如果没有用户登录...windows 不需要显示屏幕...我不敢猜测。
猜你喜欢
  • 1970-01-01
  • 2023-03-19
  • 2021-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-30
  • 1970-01-01
  • 2012-09-07
相关资源
最近更新 更多