首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将油墨画布保存到流中会导致空白.GIF

将油墨画布保存到流中会导致空白.GIF
EN

Stack Overflow用户
提问于 2017-01-09 01:32:01
回答 1查看 290关注 0票数 1

我正在用C#编写一个UWP应用程序--它将是一个闪存卡应用程序,它为卡片的“前端”和“背面”提供了两个InkCanvases。InkCanvas功能似乎运行良好。问题是,当我将InkCanvas的笔画容器“保存”到.GIF文件(如这些文档所支持的)时,生成的.GIF文件不包含墨水。相反,它们大多是空白的。这里的例子:

空白.GIF文件

UWP的开发人员能帮我指出正确的方向吗?下面是当前形式的代码:

CreateFlashCard.xaml.cs:

代码语言:javascript
复制
private void AddToDeck(object sender, RoutedEventArgs e)
    {
        // If there was ink on the canvases
        if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count > 0 
            && inkCanvas2.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
        {
            // Create the FlashCard and add it to the deck
            FlashCard newCard = new FlashCard
            {
                Front = inkCanvas.InkPresenter,
                Back = inkCanvas2.InkPresenter
            };

            // Add to the deck
            if (Deck == null)
            {
                Deck = new List<FlashCard>();
            }
            // Now Add to the Deck
            Deck.Add(newCard);

            // Save the card
            newCard.Save(_FolderName, Deck.Count-1);

            // Now make way for new InkCanvases
            inkCanvas.InkPresenter.StrokeContainer.Clear();
            inkCanvas2.InkPresenter.StrokeContainer.Clear();

        }
        // The user is adding a new card without drawing on the old one
        else
        {
            return;   
        }


    }

FlashCard.cs:

代码语言:javascript
复制
    /// <summary>
    /// Save the canvases to GIF files in the deck's folder.
    /// </summary>
    /// <param name="FolderName"> The folder to save the files in</param>
    /// <param name="CardIndex">The "number" of the card that is being saved</param>
    public async void Save(string FolderName, int CardIndex)
    {
        // Find existing folder
        StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(FolderName);
        if (folder == null)
        {
            // Error!
        } else
        {
            // Use a utility function to write to files
            // Front and Back being InkPresenters from two sep. InkCanvases
            WriteWithStream(folder, CardIndex, 'A', Front );
            WriteWithStream(folder, CardIndex, 'B', Back);

        }

    }

    private async void WriteWithStream(StorageFolder folder, int CardIndex, char Letter, InkPresenter FrontOrBack)
    {
        // Generate the ink files, A and B
        StorageFile inkFile = await folder.CreateFileAsync("Card" + CardIndex + Letter + ".gif", CreationCollisionOption.ReplaceExisting);
        // Prevent changes until we're done
        //CachedFileManager.DeferUpdates(inkFile);
        // Open a stream
        IRandomAccessStream stream = await inkFile.OpenAsync(FileAccessMode.ReadWrite);
        // Write out using the stream
        using (IOutputStream outputStream = stream.GetOutputStreamAt(0))
        {
            await FrontOrBack.StrokeContainer.SaveAsync(outputStream);
            await outputStream.FlushAsync();
        }
        // Dispose of the stream
        stream.Dispose();
        // We are now done with the file
        Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(inkFile);
    }

谢谢大家!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-09 02:26:43

解决了--我的"Save函数“的异步性质与画布的清除相冲突--我需要等待文件生成,然后清除画布。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41539793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档