8Bit Farb Bitmap in ein 8 Bit Graustufen Bitmap wandeln???
-
Hi @ all
Ich habe folgendes problem...
Wie kann ich ein 8 Bit Farb Bitmap in ein 8 Bit Graustufen Bitmap wandeln??
Hat jemand eine Idee?
Ich hoffe mir kann jemand weiterhelfen?!MFG Toby
-
Hallo,
Man könnte das hier verwenden.
void color2grey(Graphics::TBitmap *pBitmap) { LOGPALETTE* plLogPal; int ilPaletteSize; // Grösse des Buffers für die LOGPALETTE-Struktur pBitmap->PixelFormat = pf8bit; try { // Speicherbedarf für die Palette berechnen und Speicher reservieren: ilPaletteSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 255); plLogPal = (LOGPALETTE*) malloc(ilPaletteSize); if(plLogPal != NULL) { // Palette initialisieren: plLogPal->palVersion = 0x300; plLogPal->palNumEntries = 256; // Farben in der Palette mit Graustufen-Werten initialisieren: for (int ilColorIndex = 0; ilColorIndex <= 255; ilColorIndex++) { plLogPal->palPalEntry[ilColorIndex].peRed = ilColorIndex; plLogPal->palPalEntry[ilColorIndex].peGreen = ilColorIndex; plLogPal->palPalEntry[ilColorIndex].peBlue = ilColorIndex; plLogPal->palPalEntry[ilColorIndex].peFlags = PC_NOCOLLAPSE; } // Palette erzeugen und zuweisen: HPALETTE hLogPal = CreatePalette(plLogPal); if (hLogPal) pBitmap->Palette = hLogPal; // Speicher wieder freigeben: free(plLogPal); } } catch ( ... ) { ; } }Das habe ich irgendwo mal gefunden, weiß aber nicht mehr wo. Alternativ kannst du natürlich jeden Pixel einzeln wandeln.
TColor RGB2GRAY(const TColor col) { double red = (col & 0xFF) * 0.289 / 0xFF; double green = (col & 0xFF00) * 0.607 / 0xFF00; double blue = (col & 0xFF0000) * 0.114 / 0xFF0000; double gray_value = (red + green + blue); return TColor( int(gray_value*0xFF) + (int(gray_value*0xFF00) & 0xFF00) + (int(gray_value*0xFF0000) & 0xFF0000) ); } //---------------------------------------------------------------------------
-
Vielen dank für deine hilfe!!!!!!!
Ihr seit echt super!!!!!
MFG Toby