我使用的画布具有固定的宽度和高度。它的尺寸是500x500,我也想使用此方法将其保存为:

    private async void SaveasGIF(object sender, RoutedEventArgs e)
    {
        var savePicker = new Windows.Storage.Pickers.FileSavePicker();
        savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
        savePicker.FileTypeChoices.Add("Gif with embedded ISF", new[] { ".gif" });

        Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();
        if (null != file)
        {
            try
            {
                using (Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                {
                    // Truncate any existing stream in case the new file
                    // is smaller than the old file.
                    stream.Size = 0;

                    await MyInkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);
                }
                //MainPage.NotifyUser("File has been saved!", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                //MainPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
            }
        }
        SaveGIF.IsChecked = false;
    }


但是,当我这样做时,完成的.gif文件将被裁剪,并且具有421x643之类的尺寸。

我可以更改以解决此问题吗?

最佳答案

此代码await MyInkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);用于将墨水笔划的集合保存到文件中。这与将InkCanvas控件的内容渲染到图像中并不完全相同。如果笔划超出InkCanvas,则生成的.gif尺寸将大于原始InkCanvas的尺寸,反之亦然。

如果您的主要目标是将InkCanvas的内容另存为图像(而不是稍后计划加载到InkCanvas中的笔触),请使用Win2D as described here

关于c# - 节省InkCanvas会产生错误的尺寸,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47743885/

10-10 18:14