c++ - 如何将位图拉伸(stretch)到父面板中(wxWidgets 自定义)

标签 c++ codeblocks wxwidgets

Screenshot of Panel and a custom inside of it

我设置了一个 wxButton 并将位图、png 格式加载到右侧的面板。但是图像过拟合了。我想在通过按钮加载图像时将图像拉伸(stretch)到面板。

这里是按钮的功能,以防万一:

void rrFrame::testClick(wxCommandEvent& event)
{
    wxBitmap bmp;
    wxString strPath = wxT("img\\img1.png");

    bmp.LoadFile(strPath, wxBITMAP_TYPE_ANY);
    camFrame_wx->DrawBitmap(bmp, wxPoint(0, 0), false);
    //camFrame_wx is the variable name of 'Custom'
}

我想我需要在构造函数中使用拉伸(stretch)或拟合函数。如何做到这一点?

最佳答案

我认为最简单的方法是将图像文件加载到 wxImage 中首先,然后重新缩放 wxImage,最后将 wxImage 转换为 wxBitmap。像这样:

void rrFrame::testClick(wxCommandEvent& event)    
{
    wxString strPath = "img\\img1.png";
    wxImage im(strPath,wxBITMAP_TYPE_ANY );
    wxSize sz = camFrame_wx->GetSize();
    im.Rescale(sz.GetWidth(),sz.GetHeight(),wxIMAGE_QUALITY_HIGH );
    wxBitmap bmp(im);
    camFrame_wx->DrawBitmap(bmp, wxPoint(0, 0), false);
    //camFrame_wx is the variable name of 'Custom'
}

另外两条评论:

  1. 对于 wxWidgets 3.0 or later 中的字符串文字,您不应该需要 wxT 宏.
  2. 如果您需要更快的重新缩放,您可以使用其他选项,例如 wxIMAGE_QUALITY_NEAREST 而不是 wxIMAGE_QUALITY_HIGH。完整列表可用here .

关于c++ - 如何将位图拉伸(stretch)到父面板中(wxWidgets 自定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52367529/

相关文章:

c++ - std::is_base_of 用于模板类

c++ - 更改代码块中的链接器顺序

c++ - 尝试使用 EnableCheckBoxes() 时 wxWidgets 出现问题,可能是 CMake 错误

c++ - 如何绘制从 glReadPixels 捕获的屏幕截图到 wxWidgets 对话框/面板

c++ - 使用析构函数时清除成员变量

c++ - 未定义的对子类 vtable 的引用

c++ - 如何在 Code::blocks 中使用自定义项目模板

c++ - 空闲时间后 libcurl 奇怪崩​​溃

c++ - 如何使用 MinGW 编译 C++ std::thread 代码?

C++ 代码转储 "random"数据