如何从一个字节数组流中的Windows8商店应用程序 [英] How to get a stream from a byte array in a windows8 store app

查看:144
本文介绍了如何从一个字节数组流中的Windows8商店应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用下面的code得到的Metro风格应用程序的字节数组流。

I have been trying get a stream from a byte array in metro style app using the following code.

InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream();
memoryStream.AsStreamForWrite().Write(byteArray, 0, byteArray.Length);
memoryStream.Seek(0);

有执行与任何错误,但流大小为零(0)。谁能告诉我,为什么是它的大小是零?

It executes with no errors but stream size is zero (0). Can anybody tell me why is its size is zero?

推荐答案

您可以使用的 DataWriter 和的 DataReader的的类。例如...

You can use the DataWriter and DataReader classes. For example ...

// put bytes into the stream
var ms = new InMemoryRandomAccessStream();
var dw = new Windows.Storage.Streams.DataWriter(ms);
dw.WriteBytes(new byte[] { 0x00, 0x01, 0x02 });
await dw.StoreAsync();

// read them out
ms.Seek(0);
byte[] ob = new byte[ms.Size];
var dr = new Windows.Storage.Streams.DataReader(ms);
await dr.LoadAsync((uint)ms.Size);
dr.ReadBytes(ob);

这篇关于如何从一个字节数组流中的Windows8商店应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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