XE2: TPNGImage / Transparentes PNG in TImageList



  • Hallo,

    ich habe Probleme, ein TPNGImage zur Laufzeit in eine TImageList zu bekommen. Zur Entwurfszeit funktioniert das. Die Add() von TImageList lässt leider nur TBitmap und TIcon zu. Das ist glaube ich in Delphi XE2 anders, wie man das so in Foren liest.

    Ein Konvertieren in ein transparentes Icon würde auch genügen, aber da kenne ich nur den Umweg über TBitmap, und dann verliert das Bild die Transparenz.

    Für Delphi gibt es eine PngImageList Komponente, jedoch funktioniert die nur für Delphi, auf C Builder bekomme ich die nicht zum Laufen / Erzeugen
    http://cc.embarcadero.com/item/26127

    Hat das schon mal jemand hinbekommen?

    Viele Grüße



  • Habe jetzt den Umweg über ein transparentes Icon gemacht, leider.

    void TForm1::Png2Icon(TPngImage *pPng, TIcon *pIcon)
    {
        int Width, Height;
        HICON tmpIcon;
        _ICONINFO IconInfo;
        unsigned char* pAlpha;
    
        TBitmap *bmp = new TBitmap();
    
        Width = pPng->Width;
        Height = pPng->Height;
    
        bmp->PixelFormat = pf32bit;
        bmp->Width = Width;
        bmp->Height = Height;
    
        for(int y = 0; y < Height; ++y)
        {
            RGBQUAD* ptr = (RGBQUAD *) bmp->ScanLine[y];
            RGBTRIPLE* pngPtr = (RGBTRIPLE *) pPng->Scanline[y];
            pAlpha = (unsigned char*) pPng->AlphaScanline[y];
            for(int x = 0; x < Width; ++x)
            {
                ptr[x].rgbBlue = pngPtr[x].rgbtBlue;
                ptr[x].rgbGreen = pngPtr[x].rgbtGreen;
                ptr[x].rgbRed = pngPtr[x].rgbtRed;
                ptr[x].rgbReserved = pAlpha[x];
            }
        }
    
        HBITMAP hMonoBitmap = CreateBitmap(Width, Height, 1, 1, NULL);
    
        IconInfo.fIcon = true;
        IconInfo.hbmMask = hMonoBitmap;
        IconInfo.hbmColor = bmp->Handle;
        tmpIcon = CreateIconIndirect(&IconInfo);
    
        pIcon->Handle = tmpIcon;
    
        //DestroyIcon(tmpIcon);
    }
    

    Die Imagelist muss dazu angepasst werden. Eigenschaften wie folgt:

    DrawingStyle: dsTransparent
    ColorDepth: cd32Bit
    

    Edit: Achja der Speicher der Bitmaps muss noch freigegeben werden 😛


Anmelden zum Antworten