LoadedImageSurface 類別

定義

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

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

Windows 需求

裝置系列
Windows 10 Creators Update (已於 10.0.15063.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v4.0 引進)

範例

此範例示範如何將影像從本機 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時。

適用於

另請參閱