【问题标题】:How to Stretch Bitmap into Parent Panel (wxWidgets Custom)如何将位图拉伸到父面板(wxWidgets 自定义)
【发布时间】:2018-09-17 12:15:12
【问题描述】:

Screenshot of Panel and a custom inside of it

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

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

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'
}

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

【问题讨论】:

  • @RIrudezu,您可以尝试使用额外的面板或使用 wxBitmapButton。检查 sizer 如何工作的示例并做类似的事情。

标签: c++ codeblocks wxwidgets


【解决方案1】:

我认为最简单的方法是先将图像文件加载到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'
}

另外两个 cmets:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    相关资源
    最近更新 更多