//String 转 Buffer
private IBuffer GetBufferFromString(String str)
{
using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
{
using (DataWriter dataWriter = new DataWriter(memoryStream))
{
dataWriter.WriteString(str);
return dataWriter.DetachBuffer();
}
}
} //Buffer 转 String
private String GetStringFromBuffer(IBuffer buffer)
{
using (DataReader dataReader = DataReader.FromBuffer(buffer))
{
return dataReader.ReadString(buffer.Length);
}
} //Stream 转 IInputStream IInputStream inputStream = stream.AsInputStream(); //IInputStream 转 Stream stream = inputStream.AsStreamForRead(); //Stream 转 IOutputStream IOutputStream outputStream = stream.AsOutputStream(); //IOutputStream 转 Stream stream = outputStream.AsStreamForRead(); //Stream 转 IRandomAccessStream IBuffer buffer = null; var inputstream = stream.AsInputStream(); using (var dataReader = new DataReader(inputstream)) { await dataReader.LoadAsync((uint)stream.Length); buffer = dataReader.DetachBuffer(); } var iRandomAccessStream = new InMemoryRandomAccessStream(); await iRandomAccessStream.WriteAsync(buffer); // IRandomAccessStream 转 Stream stream = iRandomAccessStream.AsStream(); //Ibuffer转byte[] byte[] bytes = WindowsRuntimeBufferExtensions.ToArray(buffer,,(int)buffer.Length); //Byte[]转Ibuffer IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(bytes,,bytes.Length); //Ibuffer转Stream Stream stream = WindowsRuntimeBufferExtensions.AsStream(buffer); //Stream转Ibuffer MemoryStream memoryStream = new MemoryStream(); if (stream != null) { byte[] bytes = ReadFully(stream); if (bytes != null) { var binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(bytes); } } IBuffer buffer=WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream,,(int)memoryStream.Length); //Ibuffer转byte[] byte[] bytes=WindowsRuntimeBufferExtensions.ToArray(buffer,,(int)buffer.Length); //Byte[]转Ibuffer WindowsRuntimeBufferExtensions.AsBuffer(bytes,,bytes.Length); //Ibuffer转IrandomAccessStream InMemoryRandomAccessStream inStream = new InMemoryRandomAccessStream(); DataWriter datawriter = new DataWriter(inStream.GetOutputStreamAt()); datawriter.WriteBuffer(buffer,,buffer.Length); await datawriter.StoreAsync(); //IrandomAccessStream转Ibuffer Stream stream=WindowsRuntimeStreamExtensions.AsStreamForRead(randomStream.GetInputStreamAt()); MemoryStream memoryStream = new MemoryStream(); if (stream != null) { byte[] bytes = await ConvertStreamTobyte(stream); if (bytes != null) { var binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(bytes); } } IBuffer buffer=WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream,,(int)memoryStream.Length); //Stream转byte[] public async Task<byte[]> ConvertStreamTobyte(Stream stream) { MemoryStream ms = new MemoryStream(); await stream.CopyToAsync(ms); return ms.ToArray(); } //Byte转Stream public Stream BytesToStream(byte[] bytes) { Stream stream = new MemoryStream(bytes); return stream; } //Byte[] -> BitmapImage public async Task<BitmapImage> ByteArrayToImageAsync(byte[] pixeByte) { using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { stream.Seek(); IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(pixeByte, , pixeByte.Length); await stream.WriteAsync(buffer); BitmapImage image = new BitmapImage(); image.SetSource(stream); return image; } }

Windows 8各种流之间的转换的更多相关文章

  1. C# Stream 和 byte[] 之间的转换(文件流的应用)

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  2. c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换

    字节数组byte[]与图片image之间的转化 字节数组转换成图片 public static Image byte2img(byte[] buffer) { MemoryStream ms = ne ...

  3. 3.13. Notepad++中Windows,Unix,Mac三种格式之间的转换

    由于历史原因,导致Windows,Unix/Linux,Mac三者之间,对于文件中所用回车换行符,表示的方法,都不一样. 这就导致了很多人都会遇到回车换行符的困惑,和需要在不同格式间进行转换. 其中, ...

  4. 【转】Notepad++中Windows,Unix,Mac三种格式之间的转换

    原文网址:http://www.crifan.com/files/doc/docbook/rec_soft_npp/release/htmls/npp_func_windows_unix_mac.ht ...

  5. 将String转化成Stream,将Stream转换成String, C# Stream 和 byte[] 之间的转换(文件流的应用)

    static void Main( string[] args ) { string str = "Testing 1-2-3"; //convert string 2 strea ...

  6. Windows的本地时间(LocalTime)、系统时间(SystemTime)、格林威治时间(UTC-Time)、文件时间(FileTime)之间的转换

    今天处理了一个Bug,创建历史数据时脚本函数的起始时间不赋值或者赋0值时,计算引擎推给历史库的UTC时间为-288000000000,一开始以为是bug,经过分析后发现不赋值默认给起始时间赋0值,而此 ...

  7. Char* ,CString ,WCHAR*之间的转换

    关于Char* ,CString ,WCHAR*之间的转换问题 GDI+所有类的接口函数如果要传递字符串作为参数的话,似乎都用UNICODE串,即WCHAR*.我开始也被整得晕头转向,因为窗口编程所用 ...

  8. 关于Char* ,CString ,WCHAR*之间的转换问题

    GDI+所有类的接口函数如果要传递字符串作为参数的话,似乎都用UNICODE串,即WCHAR*.我开始也被整得晕头转向,因为窗口编程所用往往是CString,用IO流读文件数据又得到char *.得益 ...

  9. OpenGL坐标系之间的转换 http://blog.csdn.net/sac761/article/details/52179585

    1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(ModelView Transformation)和投影变换(Projection Transformation).做个比 ...

随机推荐

  1. python2.x脚本转换为python3.x脚本的方法

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/dushu990/article/details/73549174 python2.x脚本转换为pyt ...

  2. 【hdu2457】ac自动机 + dp

    传送门 题目大意: 给你一个字符主串和很多病毒串,要求更改最少的字符使得没有一个病毒串是主串的子串. 题解: ac自动机 + dp,用病毒串建好ac自动机,有毒的末尾flag置为true 构建fail ...

  3. Method and system for implementing mandatory file access control in native discretionary access control environments

    A method is provided for implementing a mandatory access control model in operating systems which na ...

  4. 6LoWPAN - Transmission of IPv6 Packets over IEEE 802.15.4 Networks

    6LoWPAN covered topics include the following:   Frame format for transmission of IPv6 packets Method ...

  5. Codeforces 444A DZY Loves Physics(图论)

    题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...

  6. hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...

  7. ASP.NET Core 配置 EF 框架服务 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core 配置 EF 框架服务 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 配置 EF 框架服务 上一章节中我们了解了 Entity ...

  8. vi学习(1)

    今天下午看了vi频繁使用的操作,现在记录,为了方便日后查询. 按vi模式.进入命令3部分. (一) 一般模式下 字符操作:上下左右箭头(或kjhl)能够实现光标上下左右移动一位. 假设想要进行多次移动 ...

  9. mingw-w64-3.10-osx10.9.sh,uninstall-macports.sh,Build NSIS on OSX

    https://gist.github.com/artynet/188bb34cfc94acdb554d283a3502770a --cross-compile-prefix=i686-w64-min ...

  10. Myeclipse2014 激活 (包括方法和工具)

    课程要求Myeclipse做各种各样的实验,对,当各种插头井.突然Myeclipse提示:使用过期,你可知道按那些个插件收了多少挫折么,怎能刚安好就用不了.可是又不想buy,所以就上网找破解咯,当中发 ...