No image handler for type 17 defined Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
rupinder
Earned a small fee
Earned a small fee
Posts: 11
Joined: Sun Aug 31, 2008 1:26 am

No image handler for type 17 defined

Post by rupinder »

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??
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

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().
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
stevelam
Earned some good credits
Earned some good credits
Posts: 114
Joined: Fri Apr 14, 2006 11:01 am

Post by stevelam »

Try adding this before your code

Code: Select all

wxImage::AddHandler(wxJPEGHandler)
That should fix it. To add all of the avalible image handlers you can use

Code: Select all

wxInitAllImageHandlers
rupinder
Earned a small fee
Earned a small fee
Posts: 11
Joined: Sun Aug 31, 2008 1:26 am

Post by rupinder »

Hey thanx.. That solved it!!
But I'm not able to find how to diplay the image, it doesn't have the show method and nothing of this sort is there in the documentation..
stevelam
Earned some good credits
Earned some good credits
Posts: 114
Joined: Fri Apr 14, 2006 11:01 am

Post by stevelam »

You could use a

Code: Select all

wxStaticBitmap
But I believe the preferred way to do it is to paint it onto a wxPanel.
rupinder
Earned a small fee
Earned a small fee
Posts: 11
Joined: Sun Aug 31, 2008 1:26 am

Post by rupinder »

I'm using this in the frame's constructor, but the frame is still blank:

wxInitAllImageHandlers();
wxImage image(wxT("cubism2.jpg"), wxBITMAP_TYPE_JPEG);
wxBitmap bitmap(image);
wxStaticBitmap(this,wxID_ANY,bitmap);
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Can you show more code? Are you using sizers?
PS: please use code tags
rupinder
Earned a small fee
Earned a small fee
Posts: 11
Joined: Sun Aug 31, 2008 1:26 am

Post by rupinder »

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)
Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver »

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:

Code: Select all

class MyFrame: public wxFrame
{
	private:
	wxImage m_image ;
}
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:

Code: Select all

	EVT_PAINT ( MyFrame::OnPaint )
3) In the implementation of the OnPaint function, use a wxDCPaint to paint your image that is a class member:

Code: Select all

MyFrame::OnPaint( wxPaintEvent& event )
{
	wxPaintDC dc ;
	wxBitmap bitmap( m_image );
	dc.Paint( ..... look for examples in google !
}
Post Reply