Author Topic: Error at image creating  (Read 2283 times)

Offline Tomi

  • Single posting newcomer
  • *
  • Posts: 7
    • My website
Error at image creating
« on: January 24, 2024, 01:48:38 pm »
Hello!

I'm using wxWidgets 3.0.x with wxSmith and I would like show images on the screen.
I wrote this code for this:

Code
class SpaceShip {
public:
    SpaceShip (int xh, int yh) {
        xplace = xh;
        yplace = yh;
    };
    int xplace, yplace;
    wxBitmap itsimage=wxImage(_T("C:\\Users\\Tomi\\Desktop\\spaceship.png")); //Warning: Unknown image data format
};
SpaceShip* spship=new SpaceShip(200,200); //If I comment out this line, everything is OK, because nothing call the class above. Maybe am'I create this on wrong place?

class BlueDot {
public:
    BlueDot(int xh, int yh) {
        xplace = xh;
        yplace = yh;
    };
    int xplace, yplace;
    wxBitmap itsimage=wxImage(_T("C:\\Users\\Tomi\\Desktop\\bluedot.png")); //Here works well...
};
std::vector<BlueDot> bluedots;

Then I paint the instances of these classes:

Code
void wxw30testprogFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(this);
    wxBitmap bitmap(spship->itsimage);
    dc.DrawBitmap(bitmap, spship->xplace,spship->yplace, false);

    for (int i=0; i<bluedots.size(); i++) {
        wxPaintDC dc(this);
        wxBitmap bitmap(bluedots[i].itsimage);
        dc.DrawBitmap(bitmap, bluedots[i].xplace,bluedots[i].yplace, false);
    };
}

At the spaceship.png I get an error message from its unknown image data format. But this method at BlueDot class works well. What is wrong?

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1629
Re: Error at image creating
« Reply #1 on: January 24, 2024, 02:04:29 pm »
Did you call wxInitAllImageHandlers()?

This is OT here, next time you should ask in the wxWidgets' forum.

Offline Tomi

  • Single posting newcomer
  • *
  • Posts: 7
    • My website
Re: Error at image creating
« Reply #2 on: January 24, 2024, 02:31:10 pm »
Yes, I tried with wxInitAllImageHandlers(), but the problem is the same.
I think, the problem really is not with the image format, but I create the instance of the SpaceShip on wrong place -  then, where is the good declaration place of it  in the code?

P.S.: sorry if this is an offtopic...  :-[

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1629
Re: Error at image creating
« Reply #3 on: January 24, 2024, 02:37:25 pm »
Programmng issues are OT here, sorry.