当前位置: 首页 > 编程语言 > C#

在c#和winrt中保存流到文件分享

时间:2023-04-10 15:11:09 C#

在c#和winrt中保存流到文件我在c#和winrt中:varstream=awaitspeech.GetSpeakStreamAsync(SpeechText.Text,language);stream是Windows.Storage.Streams.IRandomAccessStream所以我对c#和winrt完全陌生。如何将包含wav文件的流保存到文件中?在此先感谢BasiliusIRandomAccessStream有一个名为GetInputStreamAt的方法http://msdn.microsoft.com/en-US/library/windows/apps/windows.storage.streams.irandomaccessstreamIInputStreaminputStream=stream.GetInputStreamAt(0);这将为您提供一个IInputStream。IInputStream接口只定义了一种方法ReadAsync,它允许您将字节读入IBuffer对象。Windows.Storage.Stream还包括一个基于IInputStream对象的DataReader类,然后从流中读取大量.NET对象和字节数组。http://www.charlespetzold.com/blog/2011/11/080203.html,http://msdn.microsoft.com/library/windows/apps/BR208119使用(varstream=newInMemoryRandomAccessStream()){//例如,呈现pdf页面varpdfPage=document.GetPage((uint)i);等待pdfPage.RenderToStreamAsync(流);//然后,使用(varreader=newDataReader(stream)){awaitreader.LoadAsync((uint)stream.Size);varbuffer=newbyte[(int)stream.Size];reader.ReadBytes(缓冲区);等待Windows.Storage.FileIO.WriteBytesAsync(文件,缓冲区);}}现在你有一个包含所有读取字节的缓冲区。您现在可以将此缓冲区保存到文件http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.htmlvarfile=awaitWindows.Storage.ApplicationData。Current.LocalFolder.CreateFileAsync("MyWav.wav",Windows.Storage.CreationCollisionOption.ReplaceExisting);等待Windows.Storage.FileIO.WriteBytesAsync(文件,缓冲区);我无法将代码添加到评论中,所以这里是vb。网络中的代码:将gesprochenesWort变暗为Windows.Storage.Streams.IRandomAccessStreamgesprochenesWort=AwaitSprich.GetSpeakStreamAsync("DasisteinBeispieltext","de")NewWindows.Storage.Streams.DataReader(Eingabestream)AwaitDatenleser.LoadAsync(CUInt(gesprochenesWort.Size))'DimDateipufferAsByte()=NewByte(CInt(gesprochenesWort.Size)-1){}DimDateipuffer(gesprochenesWort.大小-1)AsByteDatenleser.ReadBytes(Dateipuffer)DimDateinameAsString="MybestWav.wav"DimDatei=AwaitWindows.Storage.KnownFolders.MusicLibrary.CreateFileAsync(Dateiname,Windows.Storage.CreationCollisionOption.ReplaceExisting)AwaitWindows.Storage.FileIO.WriteBytesAsync(Datei,Dateipuffer)非常感谢,Basilius上面是C#学习教程:将流保存到c#和所有winrt中文件中分享的内容,如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:

最新推荐
猜你喜欢