2010-05-19 66 views
3

我試圖在wxWidgets對話框中顯示內存中的BMP圖像,但我的嘗試都沒有成功。在wxWidgets中顯示靜態圖像?

首先,我想在我的對話框創建wxStaticBitmap控制:

// in class declaration inside header file 
    wxStaticBitmap *ibitmap; 

// in wxDialog constructor 
// MyLogo is an array of `unsigned char` 
// contains the bitmap file (Yes, the bitmap file, with BMP header) 
ibitmap = new wxStaticBitmap(mainPanel, 4000, wxBitmap(MyLogo, wxBITMAP_TYPE_BMP, 200, 62), wxPoint(10, 10), wxSize(200, 62)); 

我沒有錯誤,但圖像沒有出現。

其次,我極力把對話框EVT_PAINT內的圖像:

// in the class declaration inside header file 
    wxBitmap *ibitmap; 

// in the events declaration 
    EVT_PAINT(OnPaint) 

// in wxDialog constructor 
ibitmap = new wxBitmap(MyLogo, wxBITMAP_TYPE_BMP, 200, 62); 

// event method implementation 
void MyDialog::OnPaint(wxPaintEvent &event) 
{ 
    wxPaintDC dc(this); 
    dc.DrawBitmap(*ibitmap, 10, 10); 
} 

現在,我得到這個調試警告: http://img266.imageshack.us/img266/9512/wxerror.jpg

和調試器停在這行:

// dc.h Ln 271 
{ DoDrawBitmap(bmp, x, y, useMask); } 

任何人請指出我?

回答

1

您的位圖未正確加載。根據你想要使用wxWidgets docswxBitmap構造具有以下特徵:

wxBitmap(MyLogo, 200, 62, 3) 

假設一個RGB位圖:

wxBitmap(const char bits[], int width, int height, int depth=1) 

所以,你應該喜歡的東西而告終。

+0

我100%確定圖像是一個有效的24位位圖轉換成字節數組。 – 2010-05-19 06:37:42

+1

** 100%** ??在錯誤對話框中,顯示調用'dc.DrawBitmap'在'bmp.Ok()'上聲明,這意味着要求繪製任何位圖'dc.DrawBitmap',而不是** OK。 – heavyd 2010-05-19 10:48:59

+1

@djzmo:如果有疑問,請使用調試器瀏覽wxWidgets代碼。我發現了許多使用此方法的未記錄異常(例如wxDbTable中的未記錄項目)。 – 2010-05-19 16:21:03