vc 截屏

与上一篇相对应 截取桌面屏幕返回位图的各信息

void CatchScrBmp(BITMAP &m_bmpBit1,BYTE* &m_pBmpData1,BITMAPINFO &BitmapInfo)
    {
 
 HDC hScrDC, hMemDC; //屏幕,内存设备描述表句柄  
 
    HBITMAP hBmp; //位图句柄  
 
    int nWidth, nHeight; //屏幕的宽和高  
 
    hScrDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL); //创建屏幕设备描述表句柄  
 
    hMemDC = ::CreateCompatibleDC(hScrDC);  //创建与屏幕设备相兼容的内存设备描述表  
 
    //分别得到屏幕的宽和高  
 
    nWidth = ::GetDeviceCaps(  
 
        hScrDC,  
 
        HORZRES //  HORZRES Width, in pixels, of the screen.   
 
                //  VERTRES Height, in raster lines, of the screen.   
 
        ); 
 
    nHeight = ::GetDeviceCaps(hScrDC, VERTRES); 
 
 
 
    //创建与屏幕设备相兼容的位图  
 
    hBmp = ::CreateCompatibleBitmap( 
 
            hScrDC,        // handle to DC  
 
            nWidth,     // width of bitmap, in pixels  
 
            nHeight     // height of bitmap, in pixels  
 
            ); 
 
    ::SelectObject(hMemDC, hBmp);  //将位图选入内存设备描述表  
 
    //复制屏幕设备描述表到内存设备描述表  
 
    ::BitBlt( 
 
          hMemDC, // handle to destination DC  
 
          0,  // x-coord of destination upper-left corner  
 
          0,  // y-coord of destination upper-left corner  
 
          nWidth,  // width of destination rectangle  
 
          nHeight, // height of destination rectangle  
 
          hScrDC,  // handle to source DC  
 
          0,   // x-coordinate of source upper-left corner  
 
          0,   // y-coordinate of source upper-left corner  
 
          SRCCOPY  // raster operation code  
 
        ); 
 
 
 
    CBitmap Bmp; 
 
    Bmp.Attach(hBmp);//根据位图句柄,得到位图  
 
    BITMAP Bitmap; //位图结构  
 
    Bmp.GetBitmap(&Bitmap); //得到位图信息头和位图颜色信息  
 
      //位图信息结构,包含位图信息头和位图颜色信息  
 
    //位图信息头结构  
 
    BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFO); //本结构所占用的字节数  
 
    BitmapInfo.bmiHeader.biWidth = Bitmap.bmWidth; //位图宽度,以像素为单位  
 
    BitmapInfo.bmiHeader.biHeight = Bitmap.bmHeight; //位图高度,以像素为单位  
 
    BitmapInfo.bmiHeader.biPlanes = 1; //目标设备的级别,必须为1  
 
    BitmapInfo.bmiHeader.biBitCount = 24; //每个像素所需的位数,必须为1,4,8,24,32  
 
    BitmapInfo.bmiHeader.biCompression = 0; //位图压缩类型,必须为0,1,2  
 
    BitmapInfo.bmiHeader.biSizeImage = Bitmap.bmWidthBytes * Bitmap.bmHeight; //位图大小,以字节为单位  
 
    BitmapInfo.bmiHeader.biXPelsPerMeter = 0; //位图水平分辨率,每米像素数  
 
    BitmapInfo.bmiHeader.biYPelsPerMeter = 0; //位图垂直分辩率,每米象素数  
 
    BitmapInfo.bmiHeader.biClrUsed = 0; //位图实际使用的颜色表中的颜色数  
 
    BitmapInfo.bmiHeader.biClrImportant = 0; //位图显示过程中重要的颜色数  
 
 
 
        //位图数据信息  
 
    m_pBmpData1 = new BYTE[Bitmap.bmWidthBytes * Bitmap.bmHeight];  //用于保存位图数据的缓冲区  
 
    int n = ::GetDIBits( 
 
          hMemDC,           // handle to DC  
 
          hBmp,      // handle to bitmap  
 
          0,   // first scan line to set  
 
          Bitmap.bmHeight,   // number of scan lines to copy  
 
          m_pBmpData1,    // array for bitmap bits  
 
          &BitmapInfo, // bitmap data buffer  
 
          DIB_RGB_COLORS        // RGB or palette index  
 
        ); 
 
    m_bmpBit1 = Bitmap; 
 
 
 
    //创建了句柄,一定要释放,否则会浪费内存  
 
    ::DeleteDC(hScrDC); 
 
    ::DeleteDC(hMemDC); 


}

转载于:https://www.cnblogs.com/xiaoluyiqing/archive/2012/03/14/2396211.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值