打开发布模式后,无法将 UWP 应用程序中的 InkCanvas 内容保存到 SQLite 数据库中
Can not save InkCanvas Content in UWP App into a SQLite Datebase when Release Mode turned on
我在 UWP 应用程序中保存 InkCanvas 的内容时遇到问题。在调试模式下一切正常。发布模式无法保存
sqlite 数据库中的 blob 始终为空(在发布模式下)。
这是我的代码:
static public byte[] GetByteArray(InkCanvas CardInkCanvas) {
MemoryStream ms = new MemoryStream();
// Write the ink strokes to the output stream.
using(IOutputStream outputStream = ms.AsOutputStream()) {
CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
outputStream.FlushAsync();
}
return ms.ToArray();
}
也许 UWP 专家可以帮助我 :)
谢谢阿格雷多
I have a problem with the saving of the content of an InkCanvas in a UWP App. In Debug Mode it all works perfectly. In Release Mode, I cannot save it.
发布编译默认使用.Net Native。因此与调试模式相比有一些不同的行为。
在这种情况下,CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync
和outputStream.FlushAsync
是异步函数,您需要在它们之前添加await
。所以你的代码应该是这样的:
static public async Task<byte[]> GetByteArray(InkCanvas CardInkCanvas) {
MemoryStream ms = new MemoryStream();
// Write the ink strokes to the output stream.
using(IOutputStream outputStream = ms.AsOutputStream()) {
//Add await before async functions so that the async functions get executed before return.
await CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
await outputStream.FlushAsync();
}
return ms.ToArray();
}
我在 UWP 应用程序中保存 InkCanvas 的内容时遇到问题。在调试模式下一切正常。发布模式无法保存
sqlite 数据库中的 blob 始终为空(在发布模式下)。
这是我的代码:
static public byte[] GetByteArray(InkCanvas CardInkCanvas) {
MemoryStream ms = new MemoryStream();
// Write the ink strokes to the output stream.
using(IOutputStream outputStream = ms.AsOutputStream()) {
CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
outputStream.FlushAsync();
}
return ms.ToArray();
}
也许 UWP 专家可以帮助我 :)
谢谢阿格雷多
I have a problem with the saving of the content of an InkCanvas in a UWP App. In Debug Mode it all works perfectly. In Release Mode, I cannot save it.
发布编译默认使用.Net Native。因此与调试模式相比有一些不同的行为。
在这种情况下,CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync
和outputStream.FlushAsync
是异步函数,您需要在它们之前添加await
。所以你的代码应该是这样的:
static public async Task<byte[]> GetByteArray(InkCanvas CardInkCanvas) {
MemoryStream ms = new MemoryStream();
// Write the ink strokes to the output stream.
using(IOutputStream outputStream = ms.AsOutputStream()) {
//Add await before async functions so that the async functions get executed before return.
await CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
await outputStream.FlushAsync();
}
return ms.ToArray();
}