sim*_*314 6 qt multiple-monitors screen-capture
我正在用Q ++在Qt4中编写一个屏幕捕获应用程序.调整双屏幕时出现问题.我无法使用第二个屏幕获取图像.我尝试了ac#应用程序,它将抓取一个图像中的所有桌面,我可以从那里提取每个屏幕桌面图像.这是c#代码
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);
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是Qt中的错误或是一个功能,使用相同的窗口句柄它只重试第一个桌面,而事实上桌面是由2个屏幕组成的中继.一个想法是使用本机Windows调用并将图像保存在临时文件中并从那里加载QPixmap,但是在没有MFC的情况下将HBITMAP保存在c ++文件中并不简单.结论:您认为Qt中的错误是什么?任何想法如何解决它(没有MFC)
我最近注意到同样的问题。
我最终决定放弃 Qt 以进行屏幕截图。Qt 崩溃的另一种情况是使用 Windows Vista 或 Windows 7 的 Aero 主题时。该主题显然将所有数据渲染到后台缓冲区中,因此 Qt 截取的所有屏幕截图都是黑色的。
我可以推荐使用 ScreenShooter 类,而不是使用 Qt,如http://www.apriorit.com/our-experience/articles/9-sd-articles/193-multi-monitor-screenshot中所述。
| 归档时间: |
|
| 查看次数: |
6186 次 |
| 最近记录: |