gpt4 book ai didi

c# - 使用视觉样式截取程序的屏幕截图

转载 作者:行者123 更新时间:2023-11-30 17:43:30 27 4
gpt4 key购买 nike

我正在使用这个代码

public static Bitmap PrintWindow(IntPtr hwnd)
{
RECT rc;
GetWindowRect(hwnd, out rc);

Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format24bppRgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();

PrintWindow(hwnd, hdcBitmap, 0);

gfxBmp.ReleaseHdc(hdcBitmap);
gfxBmp.Dispose();

return bmp;
}

为了捕获程序的屏幕截图,它工作得很好,但它只需要基本的视觉样式(请检查下图,左一个是上面代码捕获的,右一个是 Alt+Prntscr 捕获的)

lRr1L.png

那么.. 有没有办法捕获具有视觉风格的程序的屏幕截图?

最佳答案

您可以尝试以下链接: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.drawtobitmap.aspx http://www.pinvoke.net/default.aspx/user32.printwindow

我用的是:

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;

...

private void CaptureWindow()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
//BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 0x00CC0020);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}

其中 memoryImage 是要打印的位图。

关于c# - 使用视觉样式截取程序的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30836884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com