InkManager.SaveAsync | saveAsync method

Applies to Windows only

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.

Syntax


inkManager.saveAsync(outputStream).done( /* Your success and error handlers */ );

Parameters

outputStream

Type: IOutputStream

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

Return value

Type: IAsyncOperationWithProgress<UInt32, UInt32>

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.

Remarks

Embedding the metadata into a 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  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.

Examples

The saveStrokes function in this example demonstrates how to:

  • Display a file save screen where the file type is constrained to 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 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.";
    }
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

Windows.UI.Input.Inking
Windows::UI::Input::Inking [C++]

Metadata

Windows.winmd

See also

InkManager
How to save ink data
Responding to pen and stylus input
Ink App sample

 

 

Show:
© 2014 Microsoft