2012-06-22 1 views
0

GetDIBits를 사용하여 현재 윈도우의 색상 내용을로드 할 수 있지만 위치에서 이미지의 색상을로드하는 방법을 알지 못합니다. 누군가 그것을 어떻게하는지 말해 줄 수 있습니까?GetDIBits를 사용하여 이미지의 픽셀 색상에 액세스하기

 char str[256]; 
     HDC hdc; 
     HWND hDesktopWnd; HDC hDesktopDC; HDC hCaptureDC; 
     HBITMAP hCaptureBitmap; BITMAPINFO bmi = {0}; 
     RGBQUAD *pPixels; 
     int nScreenWidth, nScreenHeight; 
     hdc = GetDC(hwnd); 
     GetWindowRect(hwnd,&rect); 

     hdc = GetDC(hwnd); 
     if(GetWindowRect(hwnd, &rect)) 
     { 
     width = rect.right - rect.left; 
     height = rect.bottom - rect.top; 
     } 

      nScreenWidth = GetSystemMetrics(SM_CXSCREEN); 
      nScreenHeight = GetSystemMetrics(SM_CYSCREEN); 
      hDesktopWnd = GetDesktopWindow(); 
      hDesktopDC = GetDC(hwnd); 
      hCaptureDC = CreateCompatibleDC(hDesktopDC); 
      hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight); 
      SelectObject(hCaptureDC, hCaptureBitmap); 
      BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight, hDesktopDC, 0,0, SRCCOPY|CAPTUREBLT); 

      bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); 
      bmi.bmiHeader.biWidth = nScreenWidth; 
      bmi.bmiHeader.biHeight = nScreenHeight; 
      bmi.bmiHeader.biPlanes = 1; 
      bmi.bmiHeader.biBitCount = 32; 
      bmi.bmiHeader.biCompression = BI_RGB; 

      pPixels = new RGBQUAD[nScreenWidth * nScreenHeight]; 

      ::GetDIBits(hCaptureDC, 
         hCaptureBitmap, 
         0, 
         nScreenHeight, 
         pPixels, 
         &bmi, 
         DIB_RGB_COLORS); 

나는 윈도우 프로그래밍에서 배열에

  for(int i= 0;i< nScreenHeight; i++){ 
      for(int j= 0;j< nScreenWidth; j++){ 
       col.red_palette[i][j] = pPixels[(nScreenWidth * (nScreenHeight-(i+1))) + j].rgbRed; 
       col.green_palette[i][j] = pPixels[(nScreenWidth * (nScreenHeight-(i+1))) + j].rgbGreen; 
       col.blue_palette[i][j] = pPixels[(nScreenWidth * (nScreenHeight-(i+1))) + j].rgbBlue; 
      } 
      } 


      delete [] pPixels; 
      ReleaseDC(hDesktopWnd, hDesktopDC); 
      DeleteDC(hCaptureDC); 
      DeleteObject(hCaptureBitmap); 

내가 새로 온 사람이 방법으로 색상을로드하고 바로 HDC에 이미지를로드하는 방법을 알고 싶어요. 레이몬드는 내가 여전히 활성화 된 윈도우의 색상을 캡처 아닌 이미지의거야

HBITMAP hCaptureBitmap; 
hCaptureBitmap = (HBITMAP)LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0, 
      LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE); 

로 두 번째 매개 변수를 통과 한 제안함에 따라

. 그것을 반영하기 위해 장치 핸들을 어떻게 변경합니까? Y = 0 이미지 하단에 있음을

HWND hDesktopWnd; HDC hDesktopDC; HDC hCaptureDC; 
hDesktopWnd = GetDesktopWindow(); 
hDesktopDC = GetDC(hwnd); 
hCaptureDC = CreateCompatibleDC(hDesktopDC); 

답변

1
RGBQUAD rgba = pPixels[y * nScreenWidth + x]; 

참고하지 상단 당신은 예상대로.

+0

예 제가 수행 한 작업을 보여주기 위해 코드를 업데이트했습니다. –

+0

@GambitKing, 이것이 당신이 알고 싶지 않은 것이면 나는 당신이 무엇을 요구하고 있는지 모른다. 당신은 분명하지 않습니다. –

+0

죄송합니다, 위의 코드는 배열에 현재 윈도우의 이미지 색상을로드합니다. 배열에 특정 이미지의 색상을 열고 싶습니다. 어떻게해야하는지 알고 싶습니까? –