我正在使用Native GDI +捕获窗口"屏幕上".屏幕关闭时它不起作用(生成黑色图像).我该如何解决?(我正在使用.Net 4.5)
public static Image CaptureWindow(IntPtr handle)
{
IntPtr hdcSrc = User32.GetWindowDC(handle);
RECT windowRect = new RECT();
User32.GetWindowRect(handle, ref windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc);
IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height);
IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap);
Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);
Gdi32.SelectObject(hdcDest, hOld);
Gdi32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
Image image = Image.FromHbitmap(hBitmap);
Gdi32.DeleteObject(hBitmap);
return image;
}
Run Code Online (Sandbox Code Playgroud) 我需要获得几个对象的名称.名称不能包含它们的位(16/32/64).我也是这样做的object.GetType().Name.当我使用int作为object(int.GetType().Name)时,它返回int.但是当我使用uint时它会返回uint32.我想只得到uint.有没有比String.Replace更好的方法呢?