[wxWidgets] Verlust des Alpha-Channels



  • Ich lade in einem Programm über wxImage verschiedene png. Diese sortiere ich dann auf einem Canvas und möchte dieses dann als .png speichern. Das klappt auch soweit, aber ich verliere den Alpha-Channel :(. Weil wenn ich die Textur nach OpenGL lade dann wird diese nicht mehr richtig geblendet.

    void CMainframe::OnSaveAtlas(wxCommandEvent& evt)
    {
        wxMemoryDC dc;
        dc.SetBackgroundMode(wxTRANSPARENT);
        dc.SetLogicalFunction(wxCOPY);
        wxBitmap savBMP(512,512, dc);
    
        dc.SelectObject(savBMP);
        ArrangeTextures(dc);
        savBMP.SaveFile(L"Test.png", wxBITMAP_TYPE_PNG);
    }
    
    void CMainframe::ArrangeTextures(wxDC& dc)
    {
        int raster_x = 1;
        int raster_y = 1;
    
        std::sort(m_images.begin(), m_images.end(), ImageListComp);
        for ( unsigned int i = 0; i < m_images.size(); i++ )
        {
            wxImage* img = m_images[i];
            if ( i == 0 )
            {
                dc.DrawBitmap(*img, raster_x, raster_y);
            }
            else
            {
                raster_x += m_images[i-1]->GetWidth() + 2;
                dc.DrawBitmap(*img, raster_x, raster_y);
            }
        }
    }
    

    Weiss jemand Rat? Oder eine andere Methode den DC vom Fenster zu speichern so dass der Alphakanal beibehalten wird? Beim laden dürfte der ja nicht verloren gehen laut Doku. Ich denke es liegt am Speichern, aber dazu hab ich nix gefunden. In einem Forum stand dass wxMemoryDC keinen Alpha speichert, aber der Post ist schon älter.
    Danke.
    rya.


  • Mod

    http://docs.wxwidgets.org/stable/wx_wximage.html

    Alpha channel support

    Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is in addition to a byte for the red, green and blue colour components for each pixel it also stores a byte representing the pixel opacity. An alpha value of 0 corresponds to a transparent pixel (null opacity) while a value of 255 means that the pixel is 100% opaque.

    Unlike RGB data, not all images have an alpha channel and before using GetAlpha you should check if this image contains an alpha channel with HasAlpha. Note that currently only images loaded from PNG files with transparency information will have an alpha channel but alpha support will be added to the other formats as well (as well as support for saving images with alpha channel which also isn't implemented).

    Könnte also sein, das wx da zur Zeit nur das Laden des AlphaChannels unterstützt.
    Evtl. versuchst du es mal mit einer alternativen Bildlibrary, boost::gil oder freeimage z.B.
    Oder QImage 😃

    phlox



  • Scorcher24 schrieb:

    Oder eine andere Methode den DC vom Fenster zu speichern so dass der Alphakanal beibehalten wird? Beim laden dürfte der ja nicht verloren gehen laut Doku.
    rya.

    Ich denke mal bei "draw" geht der AlphaKanal verloren.

    Hast du schon den vierten Übergabeparameter probiert ?


Anmelden zum Antworten