游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2200|回复: 1

windows GDI+的问题:如何得到一个windows屏幕图像?

[复制链接]

5

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2005-4-6 22:52:00 | 显示全部楼层 |阅读模式
windows GDI+的问题:如何得到一个windows屏幕图像?
类似于“Print Screen Sys Rq”键的屏幕拷贝功能。
有人给出了我一个方法Graphics方法: CopyFromScreen(……)。但好像.net里面没有这样的
方法。
怎么回事?
怎么回事?
[em24]

4

主题

67

帖子

67

积分

注册会员

Rank: 2

积分
67
QQ
发表于 2005-4-7 15:36:00 | 显示全部楼层

Re:windows GDI+的问题:如何得到一个windows屏幕图像?

需要使用的WIN API:
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern int BitBlt(IntPtr hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,int nXSrc,int nYSrc,UInt32 dwRop);

[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern IntPtr CreateDC(string lpszDriver,string lpszDevice,string lpszOutput,Int64 lpInitData);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,int nWidth,int nHeight);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc,IntPtr hgdiobj);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern int DeleteDC(IntPtr hdc);
==========================================
c#代码:
IntPtr hScreenDc = CreateDC("DISPLAY",null,null,0); // 创建桌面句柄
IntPtr hMemDc = CreateCompatibleDC(hScreenDc); // 创建与桌面句柄相关连的内存DC
IntPtr hBitmap = CreateCompatibleBitmap(hScreenDc, 1024, 768);
IntPtr hOldBitmap = SelectObject( hMemDc, hBitmap);
BitBlt( hMemDc, 0, 0, 1024, 768, hScreenDc, 0, 0,(UInt32)0xcc0020);
hBitmap = SelectObject( hMemDc, hOldBitmap);
DeleteDC( hScreenDc);//删除用过的对象
DeleteDC( hMemDc);//删除用过的对象
Bitmap bitmap = Bitmap.FromHbitmap(hBitmap);
bitmap.Save("screen.bmp");
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-25 04:38

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表