InkStroke to Byte Array to String [英] InkStroke to Byte Array to String

查看:53
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆