<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 10.6 圖片列表和圖標集 有時候,使用一組圖片是非常方便的.這時候,你可以直接在你的代碼中使用wxImageList,也可以和wxWidgets提供的一些控件一起使用 wxImageList,wxNotebook,wxtreeCtrl和wxListCtrl都需要wxImageList來管理它們所需要使用的圖標. 你也可使用wxImageList中的某個單獨的圖片在設備上下文上繪畫. 創建一個wxImageList需要的參數包括單個圖片的寬度和高度,一個bool值來指定是否需要指定圖片遮罩,以及這個圖片列表的初始大小(主要是為了內部優化代碼),然后一個一個的增加wxBitmap對象或者wxIcon對象.wxImageList不能直接使用wxImage 對象,你需要先將其轉換為wxBitmap對象.wxImageList::Add函數返回一個整數的索引用來代表這個剛增加的圖片,在Add函數成功返回以后,你就可以釋放原始圖片了,wxImageList已經在內部創建了一個這個圖片的拷貝. 下面是創建wxImageList以及在其中增加圖片的一些例子: ``` // 創建一個wxImageList wxImageList *imageList = new wxImageList(16, 16, true, 1); // 增加一個透明的PNG文件 wxBitmap bitmap1(wxT("image.png"), wxBITMAP_TYPE_PNG); imageList->Add(bitmap1); // 增加一個透明的來自別的bitmap的圖片 wxBitmap bitmap2(wxT("image.bmp"), wxBITMAP_TYPE_BMP); wxBitmap maskBitmap(wxT("mask.bmp"), wxBITMAP_TYPE_BMP); imageList->Add(bitmap2, maskBitmap); // 增加一個指定透明顏色的透明圖片 wxBitmap bitmap3(wxT("image.bmp"), wxBITMAP_TYPE_BMP); imageList->Add(bitmap3, *wxRED); // 增加一個圖標 #include "folder.xpm" wxIcon icon(folder_xpm); imageList->Add(icon); ``` 你可以直接把wxImageList中的圖片繪制在設備上下文上,通過指定wxIMAGELIST_DRAW_TRANSPARENT類型來指示繪制透明圖片,你還可以指定的類型包括wxIMAGELIST_DRAW_NORMAL, wxIMAGELIST_DRAW_SELECTED或者wxIMAGELIST_DRAW_FOCUSED,用來表征圖片的狀態,如下所示: ``` // 繪制列表中所有的圖片 wxClientDC dc(window); size_t i; for (i = 0; i &lt; imageList->GetImageCount(); i++) { imageList->Draw(i, dc, i*16, 0, wxIMAGELIST_DRAW_NORMAL| wxIMAGELIST_DRAW_TRANSPARENT); } ``` 要把圖片列表和notebook的TAB頁面綁定在一起,你需要創建一個包含大小為16x16的圖片的列表,然后調用 wxNotebook::SetImageList或者wxNotebook::AssignImageList將其和某個wxNotebook綁定,這兩個函數的區別在于,前者在wxNotebook釋放的時候不釋放列表,而后者在自己被釋放的時候,會同時釋放圖片列表.指定完圖片列表以后,你就可以給某個頁面指定圖標索引以便在頁面標簽上顯示圖標了,下面的代碼演示了這個過程: ``` //創建一個wxImageList wxImageList *imageList = new wxImageList(16, 16, true, 1); // 增加一些圖標 wxBitmap bitmap1(wxT("folder.png"), wxBITMAP_TYPE_PNG); wxBitmap bitmap2(wxT("file.png"), wxBITMAP_TYPE_PNG); int folderIndex = imageList->Add(bitmap1); int fileIndex = imageList->Add(bitmap2); // 創建一個擁有兩個頁面的notebook wxNotebook* notebook = new wxNotebook(parent, wxID_ANY); wxPanel* page1 = new wxPanel(notebook, wxID_ANY); wxPanel* page2 = new wxPanel(notebook, wxID_ANY); // 綁定圖片列表 notebook->AssignImageList(imageList); // Add the pages, with icons notebook->AddPage(page1, wxT("Folder options"), true, folderIndex); notebook->AddPage(page2, wxT("File options"), false, fileIndex); ``` wxtreeCtrl和wxListCtrl的使用方法和上面介紹的非常相似,也包含類似的兩種綁定方法. 如果你擁有很多圖標,有時候很難通過索引來對應到具體的圖標,你可能想編寫一個類以便通過字符串來找到某個圖片索引.下面演示了基于這個目的的一個簡單的實現: ``` #include "wx/hashmap.h" WX_DECLARE_STRING_HASH_MAP(int, IconNameToIndexHashMap); // 通過名字引用圖片的類 class IconNameToIndex { public: IconNameToIndex() {} // 在圖片列表中增加一個已經命名的圖片 void Add(wxImageList* list, const wxBitmap& bitmap, const wxString& name) { m_hashMap[name] = list->Add(bitmap); } // 在圖片列表中增加一個已命名的圖標 void Add(wxImageList* list, const wxIcon& icon, const wxString& name) { m_hashMap[name] = list->Add(icon); } // 通過名稱找到索引 int Find(const wxString& name) { return m_hashMap[name]; } private: IconNameToIndexHashMap m_hashMap; }; ``` wxIconBundle類同樣也是一個圖片列表,不過這個類的目的是為了將多個不同分辨率的圖標保存在一個類中而不是多個類中,以便系統在合適的時候根據不同的使用目的選擇一個特定的圖標.比如,在資源管理器中的圖標通常比在主窗口標題欄上顯示的圖標要大的多.下面的例子演示了其用法: ``` // 創建一個只有單個16x16圖標的圖片集 #include "file16x16.xpm" wxIconBundle iconBundle(wxIcon(file16x16_xpm)); // 在圖片集中增加一個32x32的圖片 iconBundle.Add(wxIcon(wxT("file32x32.png"), wxBITMAP_TYPE_PNG)); // 從一個包含多個圖片的文件中創建一個圖片集 wxIconBundle iconBundle2(wxT("multi-icons.tif"), wxBITMAP_TYPE_TIF); // 從圖片集中獲取指定大小的圖片,如果找不到則繼續尋找 // wxSYS_ICON_X, wxSYS_ICON_Y大小的圖片 wxIcon icon = iconBundle.GetIcon(wxSize(16,16)); // 將圖片集指定給某個主窗口 wxFrame* frame = new wxFrame(parent, wxID_ANY); frame->SetIcons(iconBundle); ``` 在windows系統上,SetIcons函數期待一個包含16x16和32x32大小的圖標的圖標集.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看