2012-01-25 11 views
5

मैंने खोज की और मुझे समझ में आया कि मुझे GetDIBits() का उपयोग करना होगा। मुझे नहीं पता कि LPVOID lpvBits पैरामीटर के साथ क्या करना है।बिटमैप के भीतर पिक्सेल रंग का उपयोग कैसे करें?

क्या कोई इसे मुझे समझा सकता है? मुझे पिक्सेल रंग की जानकारी को दो आयामी मैट्रिक्स रूप में प्राप्त करने की आवश्यकता है ताकि मैं किसी विशेष (x, y) समन्वय जोड़ी के लिए जानकारी पुनर्प्राप्त कर सकूं।

मैं Win32 API का उपयोग कर C++ में प्रोग्रामिंग कर रहा हूं।

+0

[GetDIBits और लूप के संभावित डुप्लिकेट को getpixel उपयोग करने के लिए सुझाव है कि अगर यह केवल 1 पिक्सेल आप की जरूरत है एक्स, वाई का उपयोग कर] (एच ttp: //stackoverflow.com/questions/3688409/getdibits-and-loop-through-pixels-using-x-y) –

उत्तर

1

मैं सुनिश्चित नहीं हूं कि अगर यह है कि आप क्या ढूंढ रहे हैं, लेकिन GetPixel काफी आपको क्या चाहिए होता है ... कम से कम मैं समारोह के विवरण से बता सकते हैं से

+1

आप आमतौर पर सभी पिक्सल निकालने के लिए GetPixel का उपयोग नहीं करना चाहते हैं, यह बहुत धीमी हो जाती है। – pezcode

5

पहले आप एक बिटमैप और खुले जरूरत यह

HBITMAP hBmp = (HBITMAP) LoadImage(GetModuleHandle(NULL), _T("test.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 

if(!hBmp) // failed to load bitmap 
    return false; 

//getting the size of the picture 
BITMAP bm; 
GetObject(hBmp, sizeof(bm), &bm); 
int width(bm.bmWidth), 
    height(bm.bmHeight); 

//creating a bitmapheader for getting the dibits 
BITMAPINFOHEADER bminfoheader; 
::ZeroMemory(&bminfoheader, sizeof(BITMAPINFOHEADER)); 
bminfoheader.biSize  = sizeof(BITMAPINFOHEADER); 
bminfoheader.biWidth  = width; 
bminfoheader.biHeight  = -height; 
bminfoheader.biPlanes  = 1; 
bminfoheader.biBitCount = 32; 
bminfoheader.biCompression = BI_RGB; 

bminfoheader.biSizeImage = width * 4 * height; 
bminfoheader.biClrUsed = 0; 
bminfoheader.biClrImportant = 0; 

//create a buffer and let the GetDIBits fill in the buffer 
unsigned char* pPixels = new unsigned char[(width * 4 * height)]; 
if(!GetDIBits(CreateCompatibleDC(0), hBmp, 0, height, pPixels, (BITMAPINFO*) &bminfoheader, DIB_RGB_COLORS)) // load pixel info 
{ 
    //return if fails but first delete the resources 
    DeleteObject(hBmp); 
    delete [] pPixels; // delete the array of objects 

    return false; 
} 

int x, y; // fill the x and y coordinate 

unsigned char r = pPixels[(width*y+x) * 4 + 2]; 
unsigned char g = pPixels[(width*y+x) * 4 + 1]; 
unsigned char b = pPixels[(width*y+x) * 4 + 0]; 

//clean up the bitmap and buffer unless you still need it 
DeleteObject(hBmp); 
delete [] pPixels; // delete the array of objects 
इतने कम में

, lpvBits बाहर पैरामीटर पिक्सल सूचक है, लेकिन मैं पिक्सल के माध्यम से

संबंधित मुद्दे