2014-10-19 123 views
0

我在這裏跟隨此代碼拍攝截圖。它把東西放到HDC上。我想知道如何從這個HDC中取出一些像素數據。我想將它複製到剪貼板,並將其繪製到HTML5畫布。從hdc獲取像素數據

是否必須爲HDC上的每個點運行GetPixel,這是獲取位圖數組的唯一方法嗎?

HBITMAP MakePrintScreen() 
{ 
     HWND hWindow = GetDesktopWindow(); 
     HDC hdcScreen = GetDC(hWindow); 
     RECT rect; 
     HBITMAP hbmC; 

     GetClientRect(hWindow,&rect); 

     if((hbmC = CreateCompatibleBitmap(hdcScreen,rect.right,rect.bottom)) != NULL) 
     { 
      HDC hdcC; 
      if((hdcC = CreateCompatibleDC(hdcScreen)) != NULL) 
      { 
        HBITMAP hbmOld = (HBITMAP)SelectObject(hdcC,hbmC); 

        BitBlt(hdcC,0,0,rect.right,rect.bottom,hdcScreen,0,0,SRCCOPY); 

        SelectObject(hdcC,hbmOld); 
        DeleteDC(hdcC); 
      } 
     } 

     ReleaseDC(hWindow,hdcScreen); 

     return hbmC; 
} 

回答

4

你已經取消你的呼喚GetDIBits從位圖檢索位的設備上下文位圖後。

+0

感謝arx你可以請GetDIBits進入上面的示例代碼(我實際上在js-ctypes中做這個,所以不知道c我只是從c到js-ctypes的粗暴轉換) – Noitidart 2014-10-19 12:06:17