1

我使用可以捕获笔画并保存坐标和时间等数据的应用程序(Wacom 数位板,CDL-Windows-1.0.1)。我正在尝试从 inkCanvas 中保存图片,但我总是收到错误,即 inkCanvas 不包含定义 inkPresenter。

我一直在寻找答案,我在这里发现了同样的问题如何解决这个“缺少程序集引用”错误?. 我在那里尝试了解决方案,但它不起作用,我已经安装了 Nuget Package Win2D.UWP 它没有帮助,有没有人知道我可以做什么而不是 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' 不包含 InkPresenter 的定义,并且找不到接受 InkCanvas 类型的第一个参数的可访问扩展方法 InkPresenter(您是否缺少 using 指令或程序集引用?)

4

0 回答 0