實作兩種截圖方式:
GEViewContent view = GetGEView();
if (view != null) {
ApplicationGE ge = view.GeApplication;
if (ge != null && ge.IsInitialized() > 0) {
using (SaveFileDialog sfd = new SaveFileDialog()) {
sfd.Filter = "JPG|*.jpg";
if (sfd.ShowDialog() == DialogResult.OK)
ge.SaveScreenShot(sfd.FileName, 100);
}
}
}
IntPtr hRender = view.GeRenderHWnd;
if (hRender != IntPtr.Zero) {
IntPtr hRenderDC = NativeMethods.GetWindowDC(hRender);
IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC, width, height);
IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
NativeMethods.SelectObject(hMemDC, hBitmap);
NativeMethods.BitBlt(hMemDC, 0, 0, width, height, hRenderDC, 0, 0, 0x00CC0020); // SRCCOPY
using (Bitmap bmp = Bitmap.FromHbitmap(hBitmap)) {
bmp.Save(sfd.FileName, ImageFormat.Jpeg);
}
NativeMethods.DeleteDC(hRenderDC);
NativeMethods.DeleteDC(hMemDC);
}
彩色截圖透過 GDI 複製渲染裝置內容,繞過 GE 內建限制,但受作業系統桌面合成影響,較新 OS 需改用 DWM API 或其他方案。