1

I work with application which can capture strokes and save the data such as coordinates and time (Wacom tablett, CDL-Windows-1.0.1). I am trying to save picture from inkCanvas but I always get error that inkCanvas does not contain definition inkPresenter.

I was looking for an answer, I found the same problem here How to fix this 'Missing assembly reference' error?. I tried solution there but it does not work, I have installed Nuget Package Win2D.UWP it did not help, does anyone have any idea what can I do instead of inkPresenter

private async void ButtonSavePic_Click(object sender, RoutedEventArgs e)
{
    // Get all strokes on the InkCanvas.
    IReadOnlyList<InkStroke> currentStrokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();

    // Strokes present on ink canvas.
    if (currentStrokes.Count > 0)
    {
        // Let users choose their ink file using a file picker.
        // Initialize the picker.
        Windows.Storage.Pickers.FileSavePicker savePicker =
            new Windows.Storage.Pickers.FileSavePicker();
        savePicker.SuggestedStartLocation =
            Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
        savePicker.FileTypeChoices.Add(
            "GIF with embedded ISF",
            new List<string>() { ".gif" });
        savePicker.DefaultFileExtension = ".gif";
        savePicker.SuggestedFileName = "InkSample";

        // Show the file picker.
        Windows.Storage.StorageFile file =
            await savePicker.PickSaveFileAsync();
        // When chosen, picker returns a reference to the selected file.
        if (file != null)
        {
            // Prevent updates to the file until updates are 
            // finalized with call to CompleteUpdatesAsync.
            Windows.Storage.CachedFileManager.DeferUpdates(file);
            // Open a file stream for writing.
            IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
            // Write the ink strokes to the output stream.
            using (IOutputStream outputStream = stream.GetOutputStreamAt(0))
            {
                await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream);
                await outputStream.FlushAsync();
            }
            stream.Dispose();

            // Finalize write so other apps can update file.
            Windows.Storage.Provider.FileUpdateStatus status =
                await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

            if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
            {
                // File saved.
            }
            else
            {
                // File couldn't be saved.
            }
        }
        // User selects Cancel and picker returns null.
        else
        {
            // Operation cancelled.
        }
    }
}

CS1061 'InkCanvas' does not contain a definition for InkPresenter and no accessible extension method InkPresenter accepting a first argument of type InkCanvas could be found (are you missing a using directive or an assembly reference?)

Shawn Tabrizi
  • 12,206
  • 1
  • 38
  • 69
Emil_Bayt
  • 11
  • 1

0 Answers0