InkManager.SaveAsync(IOutputStream) Method

Definition

Note

For Universal Windows app using Extensible Application Markup Language (XAML), we recommend using InkPresenter and the InkCanvas control instead of InkManager.

Asynchronously saves all InkStroke objects in the InkStroke collection that is managed by the InkManager to the specified stream.

Ink data is serialized as Ink Serialized Format (ISF) metadata and embedded into a Graphics Interchange Format (GIF) file.

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)

Parameters

outputStream
IOutputStream

The target stream. An IRandomAccessStream (requires IOutputStream) object can be specified instead.

Returns

IAsyncOperationWithProgress<UInt32,UInt32>

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

IAsyncOperationWithProgress<uint32_t,uint32_t>

The size of the saved stream and the status of the asynchronous operation as the number of bytes sent. For more information, see WriteAsync method.

Implements

Attributes

Examples

The saveStrokes function in this example demonstrates how to:

  • Display a file save screen where the file type is constrained to Graphics Interchange Format (GIF) format using the FileSavePicker object.
  • Set up an output stream through the OpenAsync method.
  • Use the SaveAsync method of an InkManager object (inkManager) to serialize the ink data to an output stream and embed it into a Graphics Interchange Format (GIF) file (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.";
    }
}

Remarks

Embedding the metadata into a Graphics Interchange Format (GIF) file enables ink to be viewed in applications that are not ink-enabled while maintaining full fidelity for ink-enabled applications. This format is ideal for transporting ink content within an HTML file and making it usable by both ink and non-ink applications.

Note

Ink Serialized Format (ISF) is the most compact persistent representation of ink. It can be embedded within a binary document format or placed directly on the Clipboard while preserving various ink properties such as pressure, width, color, tilt, twist, and so on.

Applies to

See also