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'
}
另外两条评论:
- 对于 wxWidgets 3.0 or later 中的字符串文字,您不应该需要 wxT 宏.
- 如果您需要更快的重新缩放,您可以使用其他选项,例如 wxIMAGE_QUALITY_NEAREST 而不是 wxIMAGE_QUALITY_HIGH。完整列表可用here .
关于c++ - 如何将位图拉伸(stretch)到父面板中(wxWidgets 自定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52367529/