語言

InkManager.SaveAsync(IOutputStream) 方法

定義

注意

針對使用 Extensible Application Markup Language (XAML) 的通用 Windows 應用程式,我們建議使用 InkPresenter 和 InkCanvas 控制項,而不是 InkManager。

以非同步方式將所有 InkStroke 物件儲存在 InkStroke 集合中,由 InkManager 管理至指定的資料流程。

筆跡資料會在 ISF) 中繼資料 (序列化為筆跡序列化格式,並內嵌到圖形交換格式 (GIF) 檔案中。

public:
 virtual IAsyncOperationWithProgress<unsigned int, unsigned int> ^ SaveAsync(IOutputStream ^ outputStream) = SaveAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<uint32_t, uint32_t> SaveAsync(IOutputStream const& outputStream);
/// [Windows.Foundation.Metadata.RemoteAsync]
/// [Windows.Foundation.Metadata.Overload("SaveAsync")]
IAsyncOperationWithProgress<uint32_t, uint32_t> SaveAsync(IOutputStream const& outputStream);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<uint,uint> SaveAsync(IOutputStream outputStream);
[Windows.Foundation.Metadata.RemoteAsync]
[Windows.Foundation.Metadata.Overload("SaveAsync")]
public IAsyncOperationWithProgress<uint,uint> SaveAsync(IOutputStream outputStream);
function saveAsync(outputStream)
Public Function SaveAsync (outputStream As IOutputStream) As IAsyncOperationWithProgress(Of UInteger, UInteger)

參數

outputStream
IOutputStream

目標資料流。 IRandomAccessStream (需要改為指定IOutputStream) 物件。

傳回

IAsyncOperationWithProgress<UInt32,UInt32>

Windows.Foundation.IAsyncOperationWithProgress<unsigned int,unsigned int>

IAsyncOperationWithProgress<uint32_t,uint32_t>

已儲存資料流程的大小,以及非同步作業的狀態為傳送的位元組數目。 如需詳細資訊,請參閱 WriteAsync 方法。

實作

屬性

範例

此範例中的 函 saveStrokes 式示範如何:

  • 顯示檔案儲存畫面,其中檔案類型受限於使用 FileSavePicker 物件的圖形交換格式 (GIF) 格式。
  • 透過 OpenAsync 方法設定輸出資料流程。
  • 使用 InkManager 物件的 SaveAsync 方法 (inkManager) 將筆跡資料序列化至輸出資料流程,並將其內嵌至圖形交換格式 (GIF) 檔案 (storageFile) 。
// Save all strokes owned by inkManager.
function saveStrokes()
{
    // Ensure that strokes exist before calling saveAsync.
    if (inkManager.getStrokes().size > 0)
    {
        // Set up the file save screen.
        var savePicker = Windows.Storage.Pickers.FileSavePicker();
        savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
        savePicker.fileTypeChoices.insert("GIF with embedded ISF", [".gif"]);
        savePicker.defaultFileExtension = ".gif";

        // Set up the stream.
        var saveStream = null;

        // Asynchronously save the ink data to the stream.
        savePicker.pickSaveFileAsync().done(
        function (file)
        {
            if (null !== file)
            {
                file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
                    function (stream)
                    {
                        saveStream = stream;
                        return inkManager.saveAsync(saveStream);
                    }
                ).then(
                    function ()
                    {
                        return saveStream.flushAsync(); 
                    },
                    function (e) {
                        // Override the standard saveAsync error with our own.
                        throw new Error("saveAsync");
                    }
                ).done(
                    function ()
                    {
                        statusMessage.innerText = "Strokes saved as GIF with embedded ISF (.gif).";
                        saveStream.close();
                    },
                    function (e) {
                        statusMessage.innerText = "Save: " + e.toString();
                        // Close the stream if open.
                        if (saveStream) {
                            saveStream.close();
                        }
                    }
                );
            }
        }
    );
    }
    else
    {
        statusMessage.innerText = "No strokes to save.";
    }
}

備註

將中繼資料內嵌至圖形交換格式 (GIF) 檔案,可讓筆跡在未啟用筆跡的應用程式中檢視,同時維持啟用筆跡之應用程式的完整精確度。 此格式非常適合用於傳輸 HTML 檔案內的筆跡內容,並讓筆跡和非筆跡應用程式都能使用。

注意

筆跡序列化格式 (ISF) 是最精簡的筆跡持續性標記法。 它可以內嵌在二進位檔案格式內,或直接放在剪貼簿上,同時保留各種筆跡屬性,例如壓力、寬度、色彩、傾斜、扭曲等等。

適用於

另請參閱