No image handler for type 17 defined Topic is solved
No image handler for type 17 defined
Im trying to display a simple .jpeg image but I'm getting the following warning (and the image doesnt display):
No image handler for type 17 defined
Here's the code:
wxImage image(wxT("cubism2.jpg"), wxBITMAP_TYPE_JPEG);
wxBitmap bitmap(image);
wxMemoryDC dc;
dc.SelectObject(bitmap);
dc.SetBackground(*wxWHITE_BRUSH);
dc.Clear();
dc.SelectObject(wxNullBitmap);
Is it that I need to use the .xpm equivalent of the file??
No image handler for type 17 defined
Here's the code:
wxImage image(wxT("cubism2.jpg"), wxBITMAP_TYPE_JPEG);
wxBitmap bitmap(image);
wxMemoryDC dc;
dc.SelectObject(bitmap);
dc.SetBackground(*wxWHITE_BRUSH);
dc.Clear();
dc.SelectObject(wxNullBitmap);
Is it that I need to use the .xpm equivalent of the file??
Hi!
No, you can use the jpg but you'll have to initialize the handler for this image type. The easiest to do is calling wxInitAllImageHandlers() right before loading the image, or even better, in OnInit().
No, you can use the jpg but you'll have to initialize the handler for this image type. The easiest to do is calling wxInitAllImageHandlers() right before loading the image, or even better, in OnInit().
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
Try adding this before your code
That should fix it. To add all of the avalible image handlers you can use
Code: Select all
wxImage::AddHandler(wxJPEGHandler)
Code: Select all
wxInitAllImageHandlers
You could use a
But I believe the preferred way to do it is to paint it onto a wxPanel.
Code: Select all
wxStaticBitmap
Here is the complete code:
Code: Select all
#include <wx.h>
#include <wx/dc.h>
class MyApp:public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
MyFrame();
};
MyFrame::MyFrame():wxFrame(NULL,wxID_ANY,"This is the thing")
{
wxInitAllImageHandlers();
wxImage image(wxT("cubism2.jpg"), wxBITMAP_TYPE_JPEG);
wxBitmap bitmap(image);
wxMemoryDC dc;
dc.SelectObject(bitmap);
dc.SetBackground(*wxWHITE_BRUSH);
dc.Clear();
dc.SelectObject(wxNullBitmap);
wxStaticBitmap(this,wxID_ANY,bitmap);
}
bool MyApp::OnInit()
{
MyFrame *now = new MyFrame();
now->Show(true);
return 1;
}
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
-
- Super wx Problem Solver
- Posts: 323
- Joined: Sun Jun 08, 2008 11:59 am
- Location: Bordeaux, France
What I used to do:
Instead of using wxStaticImage, the best way is to use the paint function of your MyFrame class. So:
1) Register the loaded image into a member variable of the MyFrame class:
2) Declare the event table. In this table, declare the EVT_PAINT event. Attach it a OnPaint function which is a member of the MyFrame class:
3) In the implementation of the OnPaint function, use a wxDCPaint to paint your image that is a class member:
Instead of using wxStaticImage, the best way is to use the paint function of your MyFrame class. So:
1) Register the loaded image into a member variable of the MyFrame class:
Code: Select all
class MyFrame: public wxFrame
{
private:
wxImage m_image ;
}
Code: Select all
EVT_PAINT ( MyFrame::OnPaint )
Code: Select all
MyFrame::OnPaint( wxPaintEvent& event )
{
wxPaintDC dc ;
wxBitmap bitmap( m_image );
dc.Paint( ..... look for examples in google !
}