Bitmap manipulieren
-
Ich möchte ein Programm schreiben mit dem ich ein Bitmap manipulieren kann. Mein Ansatz ist der:
1. Größe des Bitmap hohlen
2. Memory DC generieren
3. Bitmap-Objekt in Memory DC laden und DC-Handle hohlen
4. Untersuche jedes Bitmap-Pixel (GetPixel) und ändere es bei Bedarf (SetPixel)//1. Größe des Bitmap BITMAP BitmapInfo; pBitmap->GetBitmap(&BitmapInfo); //pBitmap ist ein Bitmap-Pointer //2. memory device context generieren CClientDC dc(this); CDC memoryDC; memoryDC.CreateCompatibleDC(&dc); //3. Bitmap-Objekt in device context selektieren // und Handle des device context hohlen HDC hDC = (HDC)memoryDC.SelectObject(pBitmap); COLORREF crWhite = RGB(255, 255, 255); COLORREF crGrey = RGB(212, 208, 200); COLORREF cr; int x = 0; for(int iY = 0; iY < BitmapInfo.bmHeight; iY++) { for(int iX = 0; iX < BitmapInfo.bmWidth; iX++) { //4. Hohle einzelnes Pixel -> vergleiche und ändere if( (cr = GetPixel(hDC, iX, iY)) == crWhite) SetPixel(hDC , iX, iY, crGrey); /*BYTE B = GetBValue(cr); BYTE R = GetRValue(cr); BYTE G = GetGValue(cr);*/ x++; } }Nachdem ich die Manipulation durchgeführt habe (SetPixel) möchte ich nun mein ursprüngliches Bitmap 'pButton' überschreiben. Dazu empfehlt sich:
pButton->Attach(HGDIOBJ hObject);Aber woher bekomme ich das HGDIOBJ?
-
Ganz davon einmal abgesehen, dass der obige Code nicht funktioniert
, hat jemand eine Idee oder einen Hinweis wie man so etwas macht