我尝试编写一个程序,从* .ico文件中绘制所有可能尺寸的图像。
我的代码:
<!-- 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进行测试。 (我通过在谷歌搜索找到的)
除了256x256尺寸(它不会绘制它们)之外,一切正常。
应用程序抛出此错误:DIB Header: Image width > 32767 pixels for file.
。
我的系统: