Grauwerte in 8 Bit Bitmap werden nicht richtig gespeichert



  • Hallo zusammen, ich hab das problem zwar im c++ Builder Forum gepostet, aber ich bin auf dieses verwiesen worden, es ist wahrscheinlich ein Mischproblem und hoffe hier kann mir jemand weiterhelfen.

    Ich erzeuge eben ein 8 bit Bitmap und will nun die Bilder auf der Festplatte speichern vom Dunklen bis zum Hellen.

    for(short i = 0 ; i < 256 ; i++) {
          Graphics::TBitmap *smallImg = new Graphics::TBitmap();
          smallImg->Width = 10; smallImg->Height = 14;
          smallImg->PixelFormat = pf8bit;
    
          unsigned char *ptr;
          int x=0, y=0;
          ptr = static_cast<BYTE*>(smallImg->ScanLine[y]);
          for(int j=0; j < (smallImg->Height * smallImg->Width); j++) {
             if(x == smallImg->Width) {
                y++;
                x = 0;
                ptr = static_cast<BYTE*>(smallImg->ScanLine[y]);
             }
             ptr[x]= (BYTE) i;
             x++;
          }
          smallImg->Palette = grayPal;
          smallImg->SaveToFile("clusterColor_" + IntToStr(i) + ".bmp");
       }
    

    Die Palette hab ich mit folgendem Code erzeugt:

    LOGPALETTE* pal = NULL;
        try {
           pal = (LOGPALETTE*) malloc( sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * 256);
           pal->palVersion = 0x300;
           pal->palNumEntries = 256;
           for(short i = 0 ; i < 256 ; i++) {
              pal->palPalEntry[i].peRed =  (Byte)i;
              pal->palPalEntry[i].peGreen = pal->palPalEntry[i].peRed;
              pal->palPalEntry[i].peBlue = pal->palPalEntry[i].peRed;
           }
           grayPal = CreatePalette(pal);
        }
        __finally {
           delete pal;
        }
    



  • bin ich mit diesem beitrag in diesem forum falsch?


Anmelden zum Antworten