Anyone here who uses wxWidgets? I am a newbie in wxWidgets. I have trouble in inserting an image in my application..

I am using this one:

wxImage *img;
img=new wxImage("pic.jpeg",wxBITMAP_TYPR_ANY,-1);


this code is erotic.
What would you suggest? Thanx..

Dani AI

Generated

A short, practical follow-up to 's post and the replies from and that focuses on the usual causes and quick fixes when an image will not load in wxWidgets.

Common causes (seen in many beginner reports): missing image handlers (JPEG/PNG support not initialized), filename/path problems (relative path, case sensitivity), build lacking the image library (libjpeg), and simple typos in symbol names (for example the bitmap-type constant). A simple debug checklist: confirm the image file exists with a full path, initialize image handlers early, verify the image actually loaded with the API's status check, and convert a loaded wxImage into a wxBitmap for display (wxStaticBitmap or drawing with a wxDC).

A minimal, practical flow to test the load:

wxInitAllImageHandlers();

wxImage img;
if (!img.LoadFile("/full/path/to/pic.jpeg", wxBITMAP_TYPE_ANY)) {
    // log/fail: image did not load
}

If the load succeeds but the image still does not appear, convert to a wxBitmap and use wxStaticBitmap or draw it inside OnPaint with a wxClientDC/wxPaintDC. If LoadFile always fails, check that the wxWidgets build includes JPEG support or add a JPEG handler explicitly. For more reference on handlers and image classes, see the official wxWidgets site: wxWidgets and the reference docs at wxWidgets documentation.

Recommended Answers

All 2 Replies

>this code is erotic.
Heheh.

> this code is erotic.

Ahem...I guess you meant 'erroneous'. Erotic is ah.. something else. :-)

Oh and btw, asking the same question in the would fetch you better and fast help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.