请大家提供各种方法,并分析速度 效率
因为我要着屏幕广播,需要 起码一秒四祯 
现在瓶颈 处在在将图片保存到数组中去的时候
网络和抓屏都很快
谢谢大家帮忙

解决方案 »

  1.   

    see this.
    http://www.codeproject.com/internet/remotecontrol.asp
      

  2.   

    使用标准GDI实现游戏品质的动画系统
    燕良 2002年1月
    http://www.diamondgarden.net/
    像素操作
    以上所有操作都局限于标准GDI函数,如果我们要实现更进一步的操作,例如当傍晚你希望把整个画面的颜色渲染能淡红色调,晚上的时候你要把整个画面变暗,早上再把它恢复到原来的亮度这些GDI都无法帮你做到。 如果想达到上述效果,就必须自己对像素的RGB值进行操作。
    首先让我们要得到一个Bitmap对象中的像素数据。让我们看一下具体该怎么操作。假设我们有一个mybmp是一个CBitmap对象(或者其派生类对象),下面的代码把CBitmap中的像素取出:
    BITMAP bm;
    mybmp.GetBitmap(&bm);
    BITMAPINFO binfo;
    ZeroMemory(&binfo,sizeof(BITMAPINFO));
    binfo.bmiHeader.biBitCount=24; //24bit像素格式
    binfo.bmiHeader.biCompression=0;
    binfo.bmiHeader.biHeight=-bm.bmHeight;
    binfo.bmiHeader.biPlanes=1;
    binfo.bmiHeader.biSizeImage=0;
    binfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
    binfo.bmiHeader.biWidth=bm.bmWidth;CClientDC dc(this);
    BYTE *pbuf;//用来存储像素数据
    int linebytes=(bm.bmWidth*3+3)&(~3);//4字节对齐
    int size=linebytes*bm.bmHeight;
    pbuf=new BYTE[size];
    ::GetDIBits(dc,m_bmpSword,0,bm.bmHeight,pbuf,&binfo,DIB_RGB_COLORS);上面代码执行后,我们的pbuf中就存储了从mybmp拷贝而来的像素数据,而且是24bit模式的,这样你就可以对所有这些像素进行你所需要的操作了,例如晚上了,你想把这个Bitmap变暗,我这里粗略的把每个像素的RGB值都降低一半,可以使用下面的循环:
    for(int I;I<size;I++)
    pbuf[i]=pbuf[i]/2;
    得到了像素你就得到了一切,所有操作你都可以进行,例如上面提到的标准GDI不支持的Alpha通道。
    呵呵,像素交给你了,这样我就放心了,那我走了…。。等等,你得到了这些像素,但是渲染时我们还是要使用标准GDI操作,所以好把这些像素设置回Bitmap对象中才行,好吧,这其实很简单,继续上面的代码:
    SetDIBits(dc,mybmp,0,bm.bmHeight,pbuf,&binfo,DIB_RGB_COLORS);
    最后别忘了:
    delete[] pbuf;
      

  3.   

    int BufLen;
    char *pBuf;CBitmap::GetBitmapBits( nBufKen, pBuf );
    CSocket::Send( pBuf, nBufLen );
      

  4.   

    压缩已经解决了,我使用zlib的动态联接库
      

  5.   

    zlib?干吗不用JPEG的库,zlib才能压到什么程度?如果是序列图像,甚至可以考虑用视频压缩编码,不但消除空间冗余,还消除时间冗余,Windows自己带了那么多视频编码解码器,还提供了VCM的标准接口,压缩和解压缩很方便啊。“瓶颈处在将图片保存到数组中去的时候”???呵呵,实在想不通。
      

  6.   

    jpeg是有损压缩,我们是将屏幕广播,图象不是真彩照片
    用jpeg不核算
    现在是抓下来得图保存到buf数组里得时候很慢
      

  7.   

    既然已经放在这个内存区里了直接用zlib压缩就行了,还拷贝什么啊?zlib支持对内存压缩的。
      

  8.   

    抓下的图片是放在bitmap里面的,
    bitblt操作很慢
      

  9.   

    有没有人知道如何用 DirectX抓屏的法子快不快?
      

  10.   

    好像gdi方式下要想取得图像数据只能用GetBitmapBits和GetDIBits,而这两个函数很费时,不知你是增么做的。还有,压缩数度如何?从速度上讲jpeg是肯定不行的,所以我认为压缩在这里不应该被强求。另外如果你真的能达到一秒四祯 ,能否高诉我你的方法。还有,注意你的系统资源,你说的这种方法cpu使用很容易保持在100%的.如果有什么好的方法,也希望你能告诉我,向你学习!(my email:[email protected])
    祝你好运!
      

  11.   

    我是先把截取的图片保存为文件,然后再用LZW压缩,再传送。效果不错,1.8M的位图压缩后只有50K左右,传输很快。
      

  12.   

    Delphi的库提供很详细的图形转换,利用他做个DLL用。
      

  13.   

    可以参考MSDN上关于DIBAPI和DIBUTIL的内容:
    HBITMAP DIBToBitmap(HDIB hDIB, HPALETTE hPal) 

        LPSTR       lpDIBHdr, lpDIBBits;  // pointer to DIB header, pointer to DIB bits 
        HBITMAP     hBitmap;            // handle to device-dependent bitmap 
        HDC         hDC;                    // handle to DC 
        HPALETTE    hOldPal = NULL;    // handle to a palette 
        // if invalid handle, return NULL  
        if (!hDIB) 
            return NULL; 
        // lock memory block and get a pointer to it 
        lpDIBHdr = GlobalLock(hDIB); 
        // get a pointer to the DIB bits 
        lpDIBBits = FindDIBBits(lpDIBHdr); 
        // get a DC  
        hDC = GetDC(NULL); 
        if (!hDC) 
        { 
            // clean up and return NULL 
            GlobalUnlock(hDIB); 
            return NULL; 
        } 
        // select and realize palette 
        if (hPal) 
            hOldPal = SelectPalette(hDC, hPal, FALSE); 
        RealizePalette(hDC); 
       // create bitmap from DIB info. and bits 
        hBitmap = CreateDIBitmap(hDC, (LPBITMAPINFOHEADER)lpDIBHdr, CBM_INIT, 
                lpDIBBits, (LPBITMAPINFO)lpDIBHdr, DIB_RGB_COLORS); 
        // restore previous palette 
        if (hOldPal) 
            SelectPalette(hDC, hOldPal, FALSE); 
        // clean up 
        ReleaseDC(NULL, hDC); 
        GlobalUnlock(hDIB); 
        // return handle to the bitmap 
        return hBitmap; } 
      

  14.   

    HDIB CopyScreenToDIB(LPRECT lpRect) 

        HBITMAP     hBitmap;        // handle to device-dependent bitmap 
        HPALETTE    hPalette;       // handle to palette 
        HDIB        hDIB = NULL;    // handle to DIB 
     
        // get the device-dependent bitmap in lpRect by calling 
        //  CopyScreenToBitmap and passing it the rectangle to grab 
     
        hBitmap = CopyScreenToBitmap(lpRect); 
     
        // check for a valid bitmap handle 
     
        if (!hBitmap) 
          return NULL; 
     
        // get the current palette 
     
        hPalette = GetSystemPalette(); 
     
        // convert the bitmap to a DIB 
     
        hDIB = BitmapToDIB(hBitmap, hPalette); 
     
        // clean up  
     
        DeleteObject(hPalette); 
        DeleteObject(hBitmap); 
     
        // return handle to the packed-DIB 
        return hDIB; 
    } HBITMAP CopyScreenToBitmap(LPRECT lpRect) 

        HDC         hScrDC, hMemDC;         // screen DC and memory DC 
        HBITMAP     hBitmap, hOldBitmap;    // handles to deice-dependent bitmaps 
        int         nX, nY, nX2, nY2;       // coordinates of rectangle to grab 
        int         nWidth, nHeight;        // DIB width and height 
        int         xScrn, yScrn;           // screen resolution 
     
        // check for an empty rectangle 
     
        if (IsRectEmpty(lpRect)) 
          return NULL; 
     
        // create a DC for the screen and create 
        // a memory DC compatible to screen DC 
         
        hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); 
        hMemDC = CreateCompatibleDC(hScrDC); 
     
        // get points of rectangle to grab 
     
        nX = lpRect->left; 
        nY = lpRect->top; 
        nX2 = lpRect->right; 
        nY2 = lpRect->bottom; 
     
        // get screen resolution 
     
        xScrn = GetDeviceCaps(hScrDC, HORZRES); 
        yScrn = GetDeviceCaps(hScrDC, VERTRES); 
     
        //make sure bitmap rectangle is visible 
     
        if (nX < 0) 
            nX = 0; 
        if (nY < 0) 
            nY = 0; 
        if (nX2 > xScrn) 
            nX2 = xScrn; 
        if (nY2 > yScrn) 
            nY2 = yScrn; 
     
        nWidth = nX2 - nX; 
        nHeight = nY2 - nY; 
     
        // create a bitmap compatible with the screen DC 
        hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight); 
     
        // select new bitmap into memory DC 
        hOldBitmap = SelectObject(hMemDC, hBitmap); 
     
        // bitblt screen DC to memory DC 
        BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); 
     
        // select old bitmap back into memory DC and get handle to 
        // bitmap of the screen 
         
        hBitmap = SelectObject(hMemDC, hOldBitmap); 
     
        // clean up 
     
        DeleteDC(hScrDC); 
        DeleteDC(hMemDC); 
     
        // return handle to the bitmap 
     
        return hBitmap; 

      

  15.   

    BitBlt太慢了我实验过了,有没有用DirectX方法抓的?
    保留在内存里的?谢谢大家了
      

  16.   

    mooncat2000:
    我最近也准备写个类似的程序。
    QQ:10992445 不嫌弃可以相互探讨一下