Screenshot of Panel and a custom inside of it
我设置了一个wxButton,它将位图,png格式加载到右侧的Panel中。但是图像过拟合。当按钮加载图像时,我想将图像拉伸到面板。
这里是按钮的功能,以防万一:
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或fit函数。该怎么做?
答案 0 :(得分:2)
我认为最简单的方法是先将图像文件加载到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'
}
另外两条评论: