简体   繁体   中英

WxBitmap, cannot see correctly image

I'm trying read a bitmap image and use class wxBitmap with this constructor:

wxBitmap (const char bits[], int width, int height, int depth=1)

But i cannot understand why when I call the method:

wxDC::DrawBitmap (const wxBitmap &bitmap, wxCoord x, wxCoord y, bool useMask=false)

the image is completely distorted.

Here's the code:

wxBitmap*
MyFrame::readImage(const char* filename, int x, int y)
{
    char* bits = new char[x*y];
    char byte;
    long i = 0;


    std::ifstream f(filename, std::ios::binary);
    f.seekg(54, std::ios::beg);    // skip header

    while(i < x*y)  {
        f.read((char *)&byte, sizeof(char));
        bits[i++] = byte;
    }

    f.close();

    return (new wxBitmap(bits, x, y) );
}

After that when I try to draw the bitmap nothing works.

Instead of poking inside a bitmap file and creating a wxBitmap out of the raw data, use wxImage to load the file, then convert it to a wxBitmap :

wxBitmap*
MyFrame::readImage(const char* filename)
{
    wxImage image(wxString(filename));
    return new wxBitmap(image);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM