GetDIBits



  • Hallo,

    ich möchte mit der Funktion GetDIBits die RGB Werte eines Bitmaps in einem Array speichern. Ich probiere es schon seit etlichen Tagen aber es funktioniert einfach nicht.

    CPaintDC dc(this);
    
    unsigned char *MeinArray;
    BITMAPINFO bmpInfo;
    
    CDib dib;
         dib.CreateBitmapArray(dc, bmpInfo, MeinArray);
    
    bool CDib::CreateBitmapArray(CDC &dc, 
    							 BITMAPINFO &bmpInfo, 
    							 unsigned char* &pArray)
    {
    	// Variablen deklarieren
    	HBITMAP memBitmap;
    	CDC		memDC;
    
    	// Bitmapheader
        bmpInfo.bmiHeader.biBitCount    = 24;
        bmpInfo.bmiHeader.biCompression = BI_RGB;
        bmpInfo.bmiHeader.biPlanes      = 1;
        bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
        bmpInfo.bmiHeader.biWidth       = ((rcBounds.left + rcBounds.right) / 4) * 4 + 4;
        bmpInfo.bmiHeader.biHeight      = rcBounds.top + rcBounds.bottom + 1;
    
    	memDC.CreateCompatibleDC(&dc);
    
    	// DIB - Sektion erzeugen
        memBitmap = CreateDIBSection(memDC,
                                     &bmpInfo,
                                     DIB_RGB_COLORS,
                                     0, 0, 0);
    
    	memDC.SelectObject(memBitmap);
    
        memDC.BitBlt(0, 
    				 0, 
    				 bmpInfo.bmiHeader.biWidth, 
    				 bmpInfo.bmiHeader.biHeight, 
                     &dc, 
    				 rcBounds.left, 
    				 rcBounds.top, 
    				 SRCCOPY);
    
        pArray = new unsigned char[bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biHeight * 3]; 
    
    	// Gerätekontextunabhängige Bitmap in ByteArrays kopieren
        if(GetDIBits(dc, 
    			  memBitmap, 
    			  0, 
    			  bmpInfo.bmiHeader.biHeight, 
    			  pArray,
    			  &bmpInfo, 
    			  DIB_RGB_COLORS))
    	{	
    		return true;
    	}
    	else
    	{
    		return false;
    	}
    

    Aber warum funktioniert das nicht ?



  • Sorry das rcBounds ist natürlich auch noch ein Parameter der Funktion CreateBitmapArray(..., const CRect &rcBounds)

    Gruß Ronny


Anmelden zum Antworten