LoadedImageSurface 類別

定義

表示可下載、譯碼和載入影像的組合表面。 您可以使用參考影像來源檔案的統一資源標識符 (URI) 載入影像,或提供 IRandomAccessStream

public ref class LoadedImageSurface sealed : ICompositionSurface, IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class LoadedImageSurface final : ICompositionSurface, IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class LoadedImageSurface : ICompositionSurface, System.IDisposable
Public NotInheritable Class LoadedImageSurface
Implements ICompositionSurface, IDisposable
繼承
Object Platform::Object IInspectable LoadedImageSurface
屬性
實作

範例

此範例示範如何將影像從本機 URI 載入表面,並在 CompositionSurfaceBrush 中使用它。

Compositor compositor = new Compositor();
CompositionSurfaceBrush imageBrush = compositor.CreateSurfaceBrush();

LoadedImageSurface loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/myPic.jpg"), new Size(200.0, 400.0));

// The loadedSurface currently has a size of 0x0 since it has not been downloaded, decoded and loaded to the surface yet
imageBrush.Surface = loadedSurface;

備註

LoadedImageSurface 可以從下列影像檔格式進行來源:

  • JPEG 格式 (JPEG)
  • 可攜式網路圖形 (PNG)
  • 點陣圖 (BMP)
  • 圖形交換格式 (GIF)
  • 標記的影像檔案格式 (TIFF)
  • JPEG XR
  • 圖示 (ICO)

[!注意] LoadedImageSurface 不支持動畫 GIF 影像,因此只會顯示動畫 GIF 的第一個畫面。

如果影像來源是數據流,該數據流預期會包含其中一種格式的圖像檔。

LoadedImageSurface 編碼和譯碼

映像檔的基礎編解碼器支援是由 Windows 中的 WIC) API (WINDOWS 映像元件所提供。 如需程式代碼所記載之特定影像格式的詳細資訊,請參閱 原生 WIC 編解碼器

您可以使用其中一個處理站方法,從不同類型的影像來源建立 LoadedImageSurface 的實例,並控制影像譯碼的大小上限。 如果未指定大小上限,則影像會譯碼為其自然大小。

存留期管理

使用其中一個處理站方法來建立 LoadedImageSurface 時,基礎介面會立即初始化為0x0大小,而影像內容會開始從UI線程下載和譯碼。 成功譯碼影像來源時,它會載入表面,並在填入表面時引發 LoadCompleted 事件。 在載入過程中,介面會根據影像來源的譯碼大小,從0x0調整為最終大小。

LoadedImageSurface 會自動保留其所有資源,直到其最終參考遺失為止。 不過,您可以透過 Close 方法明確處置其資源。

[!注意] Windows 10 1703 版之前,無法使用 LoadedImageSurface。 如果您的應用程式在 Microsoft Visual Studio 中的「最小平臺版本」設定小於此頁面稍後需求區塊中顯示的「引進版本」,您就無法使用此類別。

屬性

DecodedPhysicalSize

取得實體像素中譯碼影像的大小。

DecodedSize

取得裝置獨立圖元中譯碼影像的大小。

NaturalSize

取得實體圖元的影像自然大小,其定義於原始影像來源中。

方法

Close()

處置 LoadedImageSurface 和相關聯的資源。

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

StartLoadFromStream(IRandomAccessStream)

從提供的 IRandomAccessStream,將影像載入 LoadedImageSurface,其大小為影像來源中定義的自然大小。

StartLoadFromStream(IRandomAccessStream, Size)

從所需的大小上限的 IRandomAccessStream,將影像載入 LoadedImageSurface

StartLoadFromUri(Uri)

從提供的統一資源標識碼 (URI,將影像載入 LoadedImageSurface ,) 影像來源中所定義的自然大小。

StartLoadFromUri(Uri, Size)

從所提供統一資源標識碼 (URI 將影像載入 LoadedImageSurface ,) 所需的大小上限。

事件

LoadCompleted

發生於下載、譯碼並載入基礎 ICompositionSurface 時。

適用於

另請參閱