我正在用C++編寫Qt4中的屏幕捕獲應用程序。在雙屏幕上調整時遇到問題。第二個屏幕無法顯示圖像。我嘗試了一個C#應用程序,它將抓取所有桌面上的圖像,我可以從那裏提取每個屏幕桌面圖像。 這裏是C#代碼使用Qt4捕獲多個屏幕桌面圖像
using System;
using System.Drawing;
using System.Runtime.InteropServices;
public class TestGrab
{
[STAThread]
static void Main(string[] args)
{
IntPtr hDC = WindowsNative.GetDC(WindowsNative.GetDesktopWindow());
IntPtr hBitmap = WindowsNative.GetCurrentObject(hDC,
WindowsNative.OBJ_BITMAP);
System.Drawing.Bitmap imageDesktop = System.Drawing.Image.FromHbitmap(
hBitmap);
imageDesktop.Save(@"c:\zzzzdesktop.png");
}
}
public class WindowsNative
{
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr ptr);
public const int OBJ_BITMAP = 7;
[DllImport("gdi32.dll")]
public static extern IntPtr GetCurrentObject(IntPtr hdc, uint
uiObjectType);
}
Qt的代碼較小,也我測試如果本地窗口處理對桌面是從Qt的desktop0> winId(),但它們是相等的
QPixmap CaptureWinDesktop()
{
WId desktop=GetDesktopWindow();
WId desktop2=QApplication::desktop()->winId();
if(desktop!=desktop2)
{
qDebug("sunt fdiferite WId");
}
QPixmap entireDesktop= QPixmap::grabWindow(desktop);
return entireDesktop;
}
不同
我不確定這是否是Qt中的錯誤,或者是一個功能,使用相同的窗口句柄時,它只會重試第一個桌面,實際上它是由2個屏幕組成的桌面。一個想法是使用本機窗口調用並將圖像保存在臨時文件中,然後從那裏加載QPixmap,但這並不是簡單的將HBITMAP保存在沒有MFC的C++文件中。 結論:您認爲Qt中的錯誤是什麼?任何想法如何解決它(沒有MFC)
我還發現了一個使用GDI http://www.experts-exchange的例子。com/Microsoft/Development/Q_26484815.html,看底部,數字是硬編碼的,所以你必須得到尺寸並修改代碼 – simion314 2010-10-19 14:18:43