[英]windows service screen capture returns black screen
我正在嘗試創建Windows服務應用程序來捕獲屏幕。 以前我有啟動服務的問題 。 無論如何我能夠解決它,現在我有另一個問題。 現在圖像正在保存,但它保存為黑屏。 為此,在SOF中提出了很多問題,但我無法解決我的問題。
這是我到目前為止所嘗試的:
public partial class ScreenCaptureService : ServiceBase
{
private static Bitmap bmpScreenshot;
//private static Graphics gfxScreenshot;
System.Timers.Timer timer = new System.Timers.Timer();
public ScreenCaptureService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
TraceService();
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 60000;
timer.Enabled = true;
}
protected override void OnStop()
{
timer.Enabled = false;
TraceService();
}
private void TraceService()
{
Desktop userDesk = new Desktop();
userDesk.BeginInteraction();
string path = @"D:\Screen\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileName = string.Format("SCR-{0:yyyy-MM-dd_hh-mm-ss-tt}.png", DateTime.Now);
string filePath = path + fileName;
bmpScreenshot = CaptureScreen.GetDesktopImage();
bmpScreenshot.Save(filePath, ImageFormat.Png);
userDesk.EndInteraction();
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService();
}
}
我正在使用Windows 7個電腦。 我看到幾個關於the session 0 isolation feature
答案,但我無法從他們那里得到適當的解決方案。
編輯此處此服務作為session 0
運行
服務在會話0中運行,該會話具有與其他會話不同的Window Station和Desktop分配,其中用戶通過其可見桌面與系統交互。
您可能希望讓您的服務切換到活動用戶的會話以建立到其可見桌面的鏈接,以便創建它的快照 - 您的屏幕截圖代碼按原樣運行,但正在拍攝快照自己的桌面(什么都不是)。
這可能有助於為您澄清一些事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.