InkStroke to Byte Array to String [英] InkStroke to Byte Array to String
问题描述
我的项目必须序列化一个Ink Stroke并将其作为ValueSet传输
所以我的想法是从InkCanvas获得一个Byte数组ala
InkPresenter.StrokeContainer.SaveAsync(IOutputStream)
但没有得到任何结果或空字节数组
任何代码提示?
如何将Stream转换为Byte数组,我应该使用哪种流类型
-Hannes
Hi
Hannes
InkPresenter.StrokeContainer .SaveAsync(IOutputStream)用于将墨迹保存到流中。
所以你需要先创建一个流。我建议你可以使用
InMemoryRandomAccessStream 保存InkStrokes。然后你可以使用
DataReader 加载流并获取字节数组。
您可以参考以下代码:
//创建流
InMemoryRandomAccessStream testStream = new InMemoryRandomAccessStream();
using(IOutputStream outputStream = testStream.GetOutputStreamAt(0))
{
//向流中保存inkstrokes
等待inkCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream);
await outputStream.FlushAsync( );
}
//使用datareader读取流
var dr = new DataReader(testStream.GetInputStreamAt(0));
//创建字节数组
var bytes = new byte [testStream.Size];
//加载流
aw ait dr.LoadAsync((uint)testStream.Size);
//保存到字节数组
dr.ReadBytes(bytes);
                                                                                 &NB属;                               
最好的问候,
罗伊跨度>
My Project have to serialize a Ink Stroke and Transfer it as ValueSet
So my idea is to get a Byte Array from InkCanvas ala
InkPresenter.StrokeContainer.SaveAsync(IOutputStream)
but didnt get any results or empty Byte Array
Any Code hint?
how to convert the Stream to Byte Array, which stream type I should use
-Hannes
Hi Hannes
InkPresenter.StrokeContainer.SaveAsync(IOutputStream) is used to save the inkstrokes to a stream.
So you need to create a stream first. I suggest that you could use InMemoryRandomAccessStream to save the InkStrokes. Then you could use DataReader load the stream and get the byte arrays.
You could refer the following codes:
//create stream InMemoryRandomAccessStream testStream = new InMemoryRandomAccessStream(); using (IOutputStream outputStream = testStream.GetOutputStreamAt(0)) { //save inkstrokes to the stream await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream); await outputStream.FlushAsync(); } //use datareader to read the stream var dr = new DataReader(testStream.GetInputStreamAt(0)); //create byte array var bytes = new byte[testStream.Size]; //load stream await dr.LoadAsync((uint)testStream.Size); //save to byte array dr.ReadBytes(bytes);
Best regards,
Roy
这篇关于InkStroke to Byte Array to String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!