【发布时间】: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