为什么Drawbitmap在wxGTK中不显示图片 Topic is solved

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
guyanqiu
Knows some wx things
Knows some wx things
Posts: 25
Joined: Sun Jun 13, 2010 2:44 pm

为什么Drawbitmap在wxGTK中不显示图片

Post by guyanqiu » Sat Dec 10, 2011 5:12 am

Code: Select all

void imageDialog::OnButton1Click(wxCommandEvent& event)
{
    wxInitAllImageHandlers();   //Initialize graphic format handlers
    wxString caption = wxT("选择照片");
    wxString wildcard = wxT("照片(*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp|所有文件(*.*)|*.*");
    wxString defaultDir=wxT("");
    wxString defaultFileName = wxT("");
    wxFileDialog dialog(this,caption,defaultDir,defaultFileName,wildcard,wxFD_OPEN);
    if( dialog.ShowModal() == wxID_OK)
    {
        wxString FilePath_Name = dialog.GetPath();
        wxImage image(FilePath_Name);
        wxBitmap bitmap(image);
        wxClientDC dc(Panel1);
        dc.DrawBitmap(bitmap,0,0,false);
    }
}
一个button一个panel,点击按钮选择图片,然后在panel上显示图片,不知道为什么,在Windows下,wxMSW是正常工作的,在Linux下,wxGTK就不显示图片。
有谁了解么?谢谢!

samsam598
Super wx Problem Solver
Super wx Problem Solver
Posts: 324
Joined: Mon Oct 06, 2008 12:55 pm

Re: 为什么Drawbitmap在wxGTK中不显示图片

Post by samsam598 » Mon Dec 12, 2011 1:44 am

bitmap 用带参数wxBitmapType的版本试试。
Regards,
Sam
-------------------------------------------------------------------
Windows xp
VS.Net 2003/MinGW 3.4.5 C::B character set: UTF-8
wxWidgets github 3.0 RC1 Unicode Static build,Unicode Shared build.

guyanqiu
Knows some wx things
Knows some wx things
Posts: 25
Joined: Sun Jun 13, 2010 2:44 pm

Re: 为什么Drawbitmap在wxGTK中不显示图片

Post by guyanqiu » Mon Dec 12, 2011 6:22 am

samsam598 wrote:bitmap 用带参数wxBitmapType的版本试试。
就是直接用wxBitmap(const wxString& name, wxBitmapType type)来读取图片,然后再显示么?

Code: Select all

    if( dialog.ShowModal() == wxID_OK)
    {
        wxString FilePath_Name = dialog.GetPath();
        //wxImage image(FilePath_Name);
        wxBitmap bitmap(FilePath_Name,wxBITMAP_TYPE_JPEG);
        wxClientDC dc(Panel1);
        dc.DrawBitmap(bitmap,0,0,false);
    }
我晚上试一下。

guyanqiu
Knows some wx things
Knows some wx things
Posts: 25
Joined: Sun Jun 13, 2010 2:44 pm

Re: 为什么Drawbitmap在wxGTK中不显示图片

Post by guyanqiu » Tue Dec 13, 2011 12:59 am

我测试了,和用wxImage效果一样,我发现把那个文件对话框移到旁边,再打开图片,就能显示了,
我用英文也再跨平台板面问了一下,原来需要在EVT_PAINT中绘制,不然的话,重绘的时候就会把图片搞没掉,
所以之前文件对话框在显示的对话框之上,就不会显示出来图片了。
谢谢!
Windows平台和Linux平台不一样的地方,远远多过文档所说的。

Post Reply