1
저는 C#에서 UWP 응용 프로그램을 작성하고 있습니다. 카드의 "앞"과 "뒤"에 두 개의 잉크 캔버스가있는 Flashcard 응용 프로그램이 될 것입니다. InkCanvas 기능이 정상적으로 작동하는 것 같습니다. 문제는 InkCanvas의 획 컨테이너를 .GIF 파일 (documents에서 지원됨)에 "저장"할 때 생성 된 .GIF 파일에 잉크가 들어 있지 않다는 것입니다. 대신, 그들은 대부분 비어 있습니다. 여기 예 :잉크 캔버스를 저장하면 결과가 비어있게됩니다 .GIF
수 올바른 방향으로 UWP 개발자의 도움 포인트 나?
CreateFlashCard.xaml.cs :
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 :
/// <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);
}
감사합니다 모두 여기에 현재의 형태의 코드입니다!