I want to add a button to an wxAuiToolBar
that shows an icon that I created myself (I have it as the file myicon.png
with resolution 24x24).
我想在wxAuiToolBar中添加一个按钮,显示我自己创建的图标(我将其作为文件myicon.png,分辨率为24x24)。
The best I manged so far is to convert to bmp-file and use the following code for wxsmith:
我到目前为止最好的是转换为bmp文件并使用以下代码为wxsmith:
<wxsmith>
<object class="wxFrame" name="MyFrame">
<size>800,640</size>
<object class="wxAuiManager" variable="aui_manager" member="yes">
<object class="AuiManagerItem">
<object class="wxAuiToolBar" name="ID_AUITOOLBAR" variable="toolbar" member="yes">
<pos>90,3</pos>
<object class="AuiToolBarItem">
<object class="wxAuiToolBarItem" name="ID_AUITOOLBARMEASURE" variable="AuiToolBarMeasure" member="yes">
<bitmap>/home/username/project/icon.bmp</bitmap>
<handler function="OnTest" entry="EVT_TOOL" />
</object>
<label>Test</label>
</object>
</object>
</object>
</object>
</object>
</wxsmith>
Leading to the following source code:
导致以下源代码:
toolbar->AddTool(ID_AUITOOLBAR1, _("Test"),
wxBitmap(wxImage(_T("/home/username/project/icon.bmp"))), wxNullBitmap, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
However the transparency information is lost.
但是透明度信息丢失了。
If I use the png-file or convert to xpm then I get a runtime error: "../src/gtk/bitmap.cpp(626): assert "image.IsOk()" failed in wxBitmap(): invalid image"
如果我使用png文件或转换为xpm然后我得到运行时错误:“../ src / gtk / bitmap.cpp(626):断言”image.IsOk()“在wxBitmap()中失败:无效图像”
Currently I'm trying to get it working with WxSmith, but if that turns out not to be possible I'd also be happy if anyone can help me to get it working without.
目前我正在努力让它与WxSmith合作,但如果事实证明不可能,我也会很高兴,如果有人能帮助我让它无需工作。
1 个解决方案
#1
0
In order to load PNG files during run-time you need to register the PNG image handler which can be done with wxInitAllImageHandlers(). And you still should actually check that bitmap creation succeeded because it's always possible that the file wasn't found or corrupted.
为了在运行期间加载PNG文件,您需要注册PNG图像处理程序,这可以使用wxInitAllImageHandlers()来完成。而你仍然应该检查位图创建是否成功,因为它总是可能找不到或损坏了文件。
Alternatively, you can embed PNG directly in your program and then use the convenient wxBITMAP_PNG() macro to load it. In this case you can usually omit the error handling.
或者,您可以直接在程序中嵌入PNG,然后使用方便的wxBITMAP_PNG()宏来加载它。在这种情况下,您通常可以省略错误处理。
#1
0
In order to load PNG files during run-time you need to register the PNG image handler which can be done with wxInitAllImageHandlers(). And you still should actually check that bitmap creation succeeded because it's always possible that the file wasn't found or corrupted.
为了在运行期间加载PNG文件,您需要注册PNG图像处理程序,这可以使用wxInitAllImageHandlers()来完成。而你仍然应该检查位图创建是否成功,因为它总是可能找不到或损坏了文件。
Alternatively, you can embed PNG directly in your program and then use the convenient wxBITMAP_PNG() macro to load it. In this case you can usually omit the error handling.
或者,您可以直接在程序中嵌入PNG,然后使用方便的wxBITMAP_PNG()宏来加载它。在这种情况下,您通常可以省略错误处理。