在WXWIDGETS中添加图像
Add Image in wxWidgets
我刚刚开始学习wxwidgets,我正在尝试创建某种图像开启器。但是我不明白如何添加图像...我看到了一些有关wximage,wxbitmap,wxstaticbitmap的东西,但我不明白它们中的任何一个或它们之间的区别。
#include <wx/wx.h>
#include <wx/filedlg.h>
#include <wx/wfstream.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame (const wxString& event);
void OnOpen(wxCommandEvent& event);
void OnQuit(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE();
};
DECLARE_APP(MyApp);
IMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App"));
frame->Show(true);
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_OPEN, MyFrame::OnOpen)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
END_EVENT_TABLE()
void MyFrame::OnOpen(wxCommandEvent& event)
{
wxFileDialog openFileDialog(this, ("Open JPEG file"), "", "", "JPEG files (*.jpg)|*jpg", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if(openFileDialog.ShowModal() == wxID_CANCEL)
return;
wxFileInputStream input_stream(openFileDialog.GetPath());
if(!input_stream.IsOk())
{
wxLogError("Cannot Open File '%s'.", openFileDialog.GetPath());
return;
}
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
Close(true);
}
MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title)
{
wxMenuBar * menuBar = new wxMenuBar;
wxMenu * exitMenu = new wxMenu;
wxMenu * openMenu = new wxMenu;
exitMenu->Append(wxID_EXIT);
openMenu->Append(wxID_OPEN);
menuBar->Append(openMenu, "&Open");
menuBar->Append(exitMenu, "&Exit");
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText(wxT("Image Opener !"));
}
有人可以显示在WXWIDGETS上添加图像的示例吗?或将其添加到我的代码中。感谢您的帮助!
wxImage
是图像的便携式表示形式, wxBitmap
是一种平台特定但更有效的等价。一般而言,wxImage
对于使用图像数据很方便,但需要将其转换为wxBitmap
才能显示。
这两个类都是抽象的图像,而wxStaticBitmap
是显示图像的控件,即您可以在屏幕上真正看到的东西。
image
示例(在您的wxwidgets发行的样本中)显示了如何使用不同类并直接绘制图像。
wximage和wxbitmap几乎相同,它们之间的转换很容易。wxstaticbitmap用于显示WXBITMAP。它可以通过以下示例完成(staticBitMap1是您的wxstaticbitmap,btmp是您的wxbitmap):
StaticBitmap1->SetBitmap(btmp);
相关文章:
- 将图像添加到资源文件夹UWP C++
- 按下时将图像添加到按钮
- OpenCV-如何将vale添加到图像一部分的所有像素
- 如何将图像文件夹添加到CMake项目以便在c ++可执行文件中使用这些图像?
- 如何使用 GTK 将图像添加到按钮
- 使用FreeImage向图像添加文本
- MF SinkWriter mp4文件的播放持续时间是添加音频样本时的一半,图像的播放速度也是添加音频样本的两倍
- 单击QLABEL时,将图像添加到Qlabel中
- 在QML中动态添加图像对象
- 在WXWIDGETS中添加图像
- 如何在opencv中为图像添加边框,边框颜色必须与图像颜色相同
- 如何在 WinAPI 中本机将图像添加到按钮C++(没有 MFC)
- 如何将相等运算符添加到图像按钮 (JUCE)
- 当我添加OpenGL转换时,我的图像不断消失
- 在OpenCV图像中添加文本标签
- 使用 QPixmap 和 QLabel 在 Qt Creator 中以编程方式添加图像文件 (.PNG)
- 如何使用 OpenCV 为图像添加水印
- 将图像添加到乒乓球游戏
- 将图像添加到QGraphicsScene中的某个位置
- 在 CListCtrl 中为图像添加状态图标