我以前的做法是拍一张就放入文件,发现这样实在太慢,只能每秒拍摄3张,有没有办法把拍摄屏幕放入内存,等比如拍了100张在统一写入文件。
我是新手,请大虾们解释详细点,万分万分感谢。

解决方案 »

  1.   

    以前好像使用 hook 做的,最快就100ms左右一张,快不起来。
      

  2.   

    瓶颈除了写硬盘,还有压缩和抓图。所以买个快点的CPU、显卡和硬盘或许有可能超越100ms,我是5年前做的。
      

  3.   

    我这么做到极限了吗?还能改进吗?
    long CTransparentWnd::screencopy(WPARAM wParam,LPARAM lParam)
    {

    CString filename;
    CDC *pDC;
    CString string;
    string.Format("%d",lParam);
    filename="c:\\result\\"+string+".bmp";
    CWindowDC ddc(GetDesktopWindow());
        pDC =&ddc;//获取当前整个屏幕DC
        int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式
        int Width = pDC->GetDeviceCaps(HORZRES);
        int Height = pDC->GetDeviceCaps(VERTRES);
        
        CDC memDC;//内存DC
        memDC.CreateCompatibleDC(pDC);
        
        CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
        memBitmap.CreateCompatibleBitmap(pDC, Width, Height);    oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
        memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC    //以下代码保存memDC中的位图到文件
        BITMAP bmp;
        memBitmap.GetBitmap(&bmp);//获得位图信息
        
        FILE *fp = fopen(filename, "w+b");    BITMAPINFOHEADER bih = {0};//位图信息头
        bih.biBitCount = bmp.bmBitsPixel;//每个像素字节大小
        bih.biCompression = BI_RGB;
        bih.biHeight = bmp.bmHeight;//高度
        bih.biPlanes = 1;
        bih.biSize = sizeof(BITMAPINFOHEADER);
        bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;//图像数据大小
        bih.biWidth = bmp.bmWidth;//宽度
        
        BITMAPFILEHEADER bfh = {0};//位图文件头
        bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量
        bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;//文件总的大小
        bfh.bfType = (WORD)0x4d42;
        
        fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//写入位图文件头
        
        fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//写入位图信息头
        
        byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];//申请内存保存位图数据    GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, Height, p, 
            (LPBITMAPINFO) &bih, DIB_RGB_COLORS);//获取位图数据    fwrite(p, 1, bmp.bmWidthBytes * bmp.bmHeight, fp);//写入位图数据    delete [] p;    fclose(fp);    memDC.SelectObject(oldmemBitmap);     return 0;
    }UINT ComputerThreadProc(LPVOID param)
    {
    int i;
    for (i=100;i++;i<200)
    {
          CTransparentWnd* transwnd = new CTransparentWnd();
            transwnd->screencopy(0,i);
            delete transwnd;
    }
    return 0;
    }
      

  4.   

    我存不存成bmp都无所谓,大家能不能帮我优化一下算法?
    跪谢
      

  5.   

    如果用 DirextDraw技术的话,可以快点。
      

  6.   

    可以使用mirror display driver,见TightVNC.
      

  7.   

    回复人: zhujianping_es(DavidRipple) ( ) 信誉:106  2005-08-10 15:40:00  得分: 0  
       可以使用mirror display driver,见TightVNC.
      能举个例子?
     
      

  8.   

    TightVNC不是开发源代码的吗!自己Download一个看看,好像他又三种方案:
    1)Poll Screen
    2) System Hook
    3) Mirror display driverSchema 3) is best and fast.
      

  9.   

    directshow带有一个copy 屏幕的filter,在C:\DX90SDK\Samples\C++\DirectShow\Filters\PushSource目录下,名字叫pushsource