Reputation: 324
I am very new to wxWidget. I want to create a frame which display some text and a picture. I had tried to search on internet/wsWidget help but I couldn't able to find the solution. I know there are some image hander like wxPNGHandler(); but I don't know how to use it. Any simple code to display the image will be very useful.
class MyFrame : public wxFrame
{
public:
MyFrame();
}
MyFrame :: MyFrame() : wxFrame( NULL, wxID_ANY, wxT( "My wxWidget" ), wxDefaultPosition, wxSize( 290, 180 ), wxCAPTION | wxCLOSE_BOX)
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
wxString text = wxT("Text Display\n");
//Add image to display
}
Upvotes: 1
Views: 4981
Reputation: 1
You can do like this:
wxString imagePath = "path//to//your//image//example.png";
wxInitAllImageHandlers();
wxImage originalImage(imagePath, wxBITMAP_TYPE_ANY);
wxImage resizedImage = originalImage.Scale(300, 300); //resize
wxBitmap bitmap(resizedImage);
wxStaticBitmap* image;
image = new wxStaticBitmap(this, wxID_ANY, bitmap, wxPoint(220, 10), wxSize(300, 300));
It is work for me
Upvotes: 0
Reputation: 22678
You have already found wxStaticBitmap
, but the next time you have a question my advice is to search among the wxWidgets samples. For example, searching for png
in all the *.cpp
files under the samples directory would have found samples/widgets/statbmp.cpp
which would have given you the name of the control to use.
Upvotes: 3
Reputation: 324
After trying for a day, finally this one worked.
wxPNGHandler *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxStaticBitmap *image;
image = new wxStaticBitmap( this, wxID_ANY, wxBitmap("Windows_7_logo.png", wxBITMAP_TYPE_PNG), wxPoint(50,100), wxSize(100, 500));
Upvotes: 2
Reputation: 21
Try out this.
//Create a temporary (stack-allocated) wxPaintDC object wxPaintDC paintDC(this);
//Draw Background image paintDC.DrawBitmap(wxBitmap(wxImage("image.png")),0,0);
Upvotes: 1