1: GEViewContent view = GetGEView();
null)
3: {
int nWidth = view.Control.Width;
int nHeight = view.Control.Height;
6: Point pt = view.Control.PointToScreen(view.Control.Location);
int nXSrc = pt.X;
int nYSrc = pt.Y;
9:
10: IntPtr hRender = view.GeRenderHWnd;
11:
if (hRender != IntPtr.Zero)
13: {
// 取得Render DC
15: IntPtr hRenderDC = NativeMethods.GetWindowDC(hRender);
// 创建hBitmap
17: IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC, nWidth, nHeight);
// 创建MEM DC
19: IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
// 将Bitmap Select到MemDC
21: NativeMethods.SelectObject(hMemDC, hBitmap);
// 直接拷屏
23: NativeMethods.BitBlt(hMemDC, 0, 0, nWidth, nHeight,
24: hRenderDC, 0, 0, 13369376);
25:
using(Bitmap bmp = Bitmap.FromHbitmap(hBitmap))
27: {
new SaveFileDialog())
29: {
;
true;
true;
;
34:
if (sfd.ShowDialog() == DialogResult.OK)
36: {
null;
// 默认选择JPG
if (sfd.FilterIndex == 0)
40: {
41: imgFormat = ImageFormat.Jpeg;
42: }
// 选择PNG
else
45: {
46: imgFormat = ImageFormat.Png;
47: }
48: bmp.Save(sfd.FileName, imgFormat);
49: }
50: }
51:
//销毁资源
53: NativeMethods.DeleteDC(hRenderDC);
54: NativeMethods.DeleteDC(hMemDC);
55: }
56: }
请发表评论