檢視原始碼 wxBitmap (wx v2.4.3)

這個類別封裝了平台相依點陣圖的概念,無論是單色、彩色或是具有 Alpha 通道支援的彩色。

如果您需要直接存取點陣圖資料,而不是使用 wxMemoryDC 繪製到它,您需要使用 wxPixelData (在 wx 中未實作) 類別(對於 RGB 點陣圖,使用 wxNativePixelData,對於具有額外 Alpha 通道的點陣圖,使用 wxAlphaPixelData)。

請注意,許多 wxBitmap 函式會接收一個 type 參數,該參數是 ?wxBitmapType 列舉的值。這些值的有效性取決於您的程式執行的平台和 wxWidgets 的組態。如果使用了所有可能的 wxWidgets 設定

  • wxMSW 支援 BMP 和 ICO 檔案、BMP 和 ICO 資源;

  • wxGTK 支援 gdk-pixbuf 支援的任何檔案;

  • wxMac 支援 PICT 資源;

  • wxX11 支援 XPM 檔案、XPM 資料、XBM 資料;

此外,wxBitmap 可以載入和儲存 wxImage 可以處理的所有格式;請參閱 wxImage 以取得更多資訊。當然,您必須載入 wxImage 處理器(請參閱 ?wxInitAllImageHandlers() 和 wxImage::AddHandler(在 wx 中未實作))。請注意,給定 wxWidgets 連接埠的所有可用的 wxBitmapHandlers 會在啟動時自動載入,因此您不需要使用 wxBitmap::AddHandler(在 wx 中未實作)。

關於 wxImagewxBitmap 之間的差異:wxImage 僅是 RGB 位元組的緩衝區,並具有可選的 Alpha 位元組緩衝區。它是通用的、平台獨立和影像檔案格式獨立的程式碼。它包括用於縮放、調整大小、裁剪和其他影像資料操作的通用程式碼。另一方面,wxBitmap 旨在作為任何原生影像格式的包裝器,這種格式可以最快速/最容易地繪製到 DC 或成為在 wxMemoryDC 上執行的繪圖操作的目標。透過像這樣在 wxImage/wxBitmap 之間拆分職責,可以更輕鬆地使用所有平台和影像類型共用的通用程式碼進行通用操作,並在需要效能或相容性的情況下使用平台特定的程式碼。

預定義物件(包含 wx.hrl):?wxNullBitmap

參見

wxWidgets 文件:wxBitmap

摘要

函式

從平台相依點陣圖建立影像。

從圖示建立點陣圖。

這是一個為了方便起見而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

建立與給定 DC 相容的點陣圖,繼承其放大倍數。

摧毀物件

取得點陣圖的色彩深度。

取得點陣圖的高度 (以像素為單位)。

取得相關聯的遮罩(如果有的話),該遮罩可能從檔案載入或為點陣圖設定。

取得相關聯的調色盤(如果有的話),該調色盤可能從檔案載入或為點陣圖設定。

只要矩形完全屬於點陣圖,則返回目前點陣圖的子點陣圖。

取得點陣圖的寬度 (以像素為單位)。

如果存在點陣圖資料,則返回 true。

從檔案或資源載入點陣圖。

預設建構函式。

從給定影像建立此點陣圖物件。

建立新的點陣圖。

從給定陣列 bits 建立點陣圖。

等同於:isOk/1

將點陣圖儲存到指定檔案中。

設定此點陣圖的遮罩。

設定相關聯的調色盤。

類型

-type wxBitmap() :: wx:wx_object().

函式

-spec convertToImage(This) -> wxImage:wxImage() when This :: wxBitmap().

從平台相依點陣圖建立影像。

這會保留遮罩資訊,以便點陣圖和影像可以在這方面來回轉換而不會遺失資訊。

連結到此函式

copyFromIcon(This, Icon)

檢視原始碼
-spec copyFromIcon(This, Icon) -> boolean() when This :: wxBitmap(), Icon :: wxIcon:wxIcon().

從圖示建立點陣圖。

-spec create(This, Sz) -> boolean() when This :: wxBitmap(), Sz :: {W :: integer(), H :: integer()}.

等同於 create(This, Sz, [])

-spec create(This, Width, Height) -> boolean()
                when This :: wxBitmap(), Width :: integer(), Height :: integer();
            (This, Sz, [Option]) -> boolean()
                when
                    This :: wxBitmap(),
                    Sz :: {W :: integer(), H :: integer()},
                    Option :: {depth, integer()}.

這是一個為了方便起見而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

-spec create(This, Width, Height, [Option]) -> boolean()
                when
                    This :: wxBitmap(),
                    Width :: integer(),
                    Height :: integer(),
                    Option :: {depth, integer()};
            (This, Width, Height, Dc) -> boolean()
                when This :: wxBitmap(), Width :: integer(), Height :: integer(), Dc :: wxDC:wxDC().

建立與給定 DC 相容的點陣圖,繼承其放大倍數。

傳回值:如果建立成功,則為 true。

自:3.1.0 起

-spec destroy(This :: wxBitmap()) -> ok.

摧毀物件

-spec getDepth(This) -> integer() when This :: wxBitmap().

取得點陣圖的色彩深度。

值 1 表示單色點陣圖。

-spec getHeight(This) -> integer() when This :: wxBitmap().

取得點陣圖的高度 (以像素為單位)。

參見:getWidth/1

-spec getMask(This) -> wxMask:wxMask() when This :: wxBitmap().

取得相關聯的遮罩(如果有的話),該遮罩可能從檔案載入或為點陣圖設定。

參見

-spec getPalette(This) -> wxPalette:wxPalette() when This :: wxBitmap().

取得相關聯的調色盤(如果有的話),該調色盤可能從檔案載入或為點陣圖設定。

參見:wxPalette

連結到此函式

getSubBitmap(This, Rect)

檢視原始碼
-spec getSubBitmap(This, Rect) -> wxBitmap()
                      when
                          This :: wxBitmap(),
                          Rect :: {X :: integer(), Y :: integer(), W :: integer(), H :: integer()}.

只要矩形完全屬於點陣圖,則返回目前點陣圖的子點陣圖。

此函式會保留位元深度和遮罩資訊。

-spec getWidth(This) -> integer() when This :: wxBitmap().

取得點陣圖的寬度 (以像素為單位)。

參見:getHeight/1

-spec isOk(This) -> boolean() when This :: wxBitmap().

如果存在點陣圖資料,則返回 true。

-spec loadFile(This, Name) -> boolean() when This :: wxBitmap(), Name :: unicode:chardata().

等同於 loadFile(This, Name, [])

-spec loadFile(This, Name, [Option]) -> boolean()
                  when This :: wxBitmap(), Name :: unicode:chardata(), Option :: {type, wx:wx_enum()}.

從檔案或資源載入點陣圖。

傳回值:如果操作成功,則為 true,否則為 false。

備註:如果存在(特別是對於彩色 Windows 點陣圖)且程式碼支援,則調色盤可以與點陣圖相關聯。您可以使用 getPalette/1 成員來檢查是否已建立一個。

參見:saveFile/4

-spec new() -> wxBitmap().

預設建構函式。

建構一個沒有資料的點陣圖物件;後續必須呼叫賦值或另一個成員函式,例如 create/4loadFile/3

-spec new(Name) -> wxBitmap() when Name :: unicode:chardata();
         (Sz) -> wxBitmap() when Sz :: {W :: integer(), H :: integer()};
         (Img) -> wxBitmap() when Img :: wxImage:wxImage() | wxBitmap:wxBitmap().
-spec new(Width, Height) -> wxBitmap() when Width :: integer(), Height :: integer();
         (Name, [Option]) -> wxBitmap() when Name :: unicode:chardata(), Option :: {type, wx:wx_enum()};
         (Sz, [Option]) -> wxBitmap()
             when Sz :: {W :: integer(), H :: integer()}, Option :: {depth, integer()};
         (Img, [Option]) -> wxBitmap() when Img :: wxImage:wxImage(), Option :: {depth, integer()}.

從給定影像建立此點陣圖物件。

必須這樣做才能實際顯示影像,因為您無法直接在視窗上繪製影像。

產生的點陣圖將使用提供的色彩深度(如果深度為 ?wxBITMAP_SCREEN_DEPTH,則使用目前系統的色彩深度),這表示可能會發生色彩縮減。

在 Windows 上,如果存在調色盤(使用 SetPalette 設定),則會在建立 wxBitmap 時使用(在 8 位元顯示模式下最有用)。在其他平台上,目前會忽略調色盤。

-spec new(Bits, Width, Height) -> wxBitmap()
             when Bits :: binary(), Width :: integer(), Height :: integer();
         (Width, Height, [Option]) -> wxBitmap()
             when Width :: integer(), Height :: integer(), Option :: {depth, integer()}.

建立新的點陣圖。

?wxBITMAP_SCREEN_DEPTH 的深度表示目前螢幕或視覺的深度。

某些平台僅支援單色 1 和目前色彩設定的 ?wxBITMAP_SCREEN_DEPTH。

MSW、Mac 和 GTK+ 支援包含 Alpha 通道的深度 32。

連結到此函式

new(Bits, Width, Height, Options)

檢視原始碼
-spec new(Bits, Width, Height, [Option]) -> wxBitmap()
             when
                 Bits :: binary(), Width :: integer(), Height :: integer(), Option :: {depth, integer()}.

從給定陣列 bits 建立點陣圖。

您應該僅將此函式用於可攜式程式中的單色點陣圖(深度 1):在這種情況下,bits 參數應包含 XBM 影像。

對於其他位元深度,其行為是平台相依的:在 Windows 下,資料會直接傳遞到基礎的 CreateBitmap() API,而不會進行任何變更。在其他平台下,只能使用此建構函式建立單色點陣圖,並且應使用 wxImage 從靜態資料建立彩色點陣圖。

-spec ok(This) -> boolean() when This :: wxBitmap().

等同於:isOk/1

連結到此函式

saveFile(This, Name, Type)

檢視原始碼
-spec saveFile(This, Name, Type) -> boolean()
                  when This :: wxBitmap(), Name :: unicode:chardata(), Type :: wx:wx_enum().

等同於 saveFile(This, Name, Type, [])

-spec saveFile(This, Name, Type, [Option]) -> boolean()
                  when
                      This :: wxBitmap(),
                      Name :: unicode:chardata(),
                      Type :: wx:wx_enum(),
                      Option :: {palette, wxPalette:wxPalette()}.

將點陣圖儲存到指定檔案中。

傳回值:如果操作成功,則為 true,否則為 false。

備註:根據 wxWidgets 的組態方式,並非所有格式都可用。

參見:loadFile/3

-spec setDepth(This, Depth) -> ok when This :: wxBitmap(), Depth :: integer().

已棄用

此函式自 3.1.2 版起已棄用,尺寸和深度只能在建構時設定。

設定深度成員(不影響點陣圖資料)。

連結到此函式

setHeight(This, Height)

檢視原始碼
-spec setHeight(This, Height) -> ok when This :: wxBitmap(), Height :: integer().

已棄用

此函式自 3.1.2 版起已棄用,尺寸和深度只能在建構時設定。

設定高度成員(不影響點陣圖資料)。

-spec setMask(This, Mask) -> ok when This :: wxBitmap(), Mask :: wxMask:wxMask().

設定此點陣圖的遮罩。

備註:一旦呼叫此函式,點陣圖物件便擁有遮罩。

注意:也可以為具有 Alpha 通道的點陣圖設定遮罩,但不建議在 wxMSW 下執行此操作,因為繪製此類點陣圖的效能不是很好。

參見

連結到此函式

setPalette(This, Palette)

檢視原始碼
-spec setPalette(This, Palette) -> ok when This :: wxBitmap(), Palette :: wxPalette:wxPalette().

設定相關聯的調色盤。

(在 GTK+ 下未實作)。

參見:wxPalette

-spec setWidth(This, Width) -> ok when This :: wxBitmap(), Width :: integer().

已棄用

此函式自 3.1.2 版起已棄用,尺寸和深度只能在建構時設定。

設定寬度成員(不影響點陣圖資料)。