Question

I tried to write a program to draw all possible sizes of an image from *.ico file.

My code for this:

<!-- language: lang-cpp -->

#include <wx/wx.h>
#include <wx/colour.h>
#include <wx/filesys.h>

wxString path("c:\\...\\*.ico");

class MyApp: public wxApp
{
    virtual bool OnInit();
};

class MyFrame: public wxFrame
{
public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    void paint(wxPaintEvent& event);
private:
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_PAINT(MyFrame::paint)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame("ICO Test", wxPoint(50, 50), wxSize(600,300) );
    frame->Show(true);
    SetTopWindow(frame);
    return true;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame( NULL, -1, title, pos, size )
{
    wxInitAllImageHandlers();
}


void MyFrame::paint(wxPaintEvent& event)
{
    wxPaintDC dc(this);

    int count = wxImage::GetImageCount(path, wxBITMAP_TYPE_ICO);
    dc.DrawText(wxString::Format(wxT("count is: %ld"), count), 40, 20);
    int x_pos = 20;
    for (int i = 0; i < count; ++i)
    {
        wxImage image;
        if (image.LoadFile(path, wxBITMAP_TYPE_ICO, i ))
        {
            wxIcon icon;
            icon.CopyFromBitmap(wxBitmap(image));
            dc.DrawIcon(icon, wxPoint(x_pos, 40));
            int h = icon.GetHeight();
            dc.DrawText(wxString::Format(wxT("%ld"), h), x_pos + 3, 45 + h);
            x_pos += (icon.GetWidth() + 4);
        }
    }
}

Icon for testing. (which I found by searching on Google)

All works fine except 256x256 size (it doesn't draw them).

The application throws this error: DIB Header: Image width > 32767 pixels for file..

My system:

  • Windows 7 x64
  • MinGW 4.8.2
  • wxWidgets 3.0
Was it helpful?

Solution

This looks like a bug in wxWidgets, so you should report it, ideally providing a SSCCE and at least the ICO file showing the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top