memorystream

MemoryStream: why convert to byte after readByte

╄→гoц情女王★ 提交于 2019-12-01 15:14:38
In this example from MS , you'll notice that after we read a byte from memory stream, it goes into an int which must then be converted to byte. It stikes me as strange that a function like .ReadByte() doesn't return a byte in the first place. Is there a reason why MS did it this way? // Read the remaining bytes, byte by byte. while(count < memStream.Length) { byteArray[count++] = Convert.ToByte(memStream.ReadByte()); } a thought occured to me. Perhaps this comes down to usage. Perhaps ReadByte() is often used to retrieve short lengths, which subsequents get consumed in the retrieve via length

Create .wav from multiple sine waves and play all at once [closed]

南楼画角 提交于 2019-12-01 14:49:00
I'm wondering if there is a way to adapt the code shown here so that I can basically make an array of beeps and play them all at once. I tried making global MemoryStream and BinaryWriter to use, calculating everything ahead of time for the size but it was even slower than 1 beep at a time and didn't seem to work. After that, I tried writing the MemoryStream to a byte array but that did the same as making globals for the stream/writer. How can I edit the code to get the MemoryStream to hold multiple beeps and play them all at once? Here is a modification to create the song from beeps: void Main

Serializing a memorystream object to string

末鹿安然 提交于 2019-12-01 14:15:13
问题 Right now I'm using XmlTextWriter to convert a MemoryStream object into string. But I wan't to know whether there is a faster method to serialize a memorystream to string. I follow the code given here for serialization - http://www.eggheadcafe.com/articles/system.xml.xmlserialization.asp Edited Stream to String ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { string content = sr.ReadToEnd(); SaveInDB(ms); } String to Stream string content = GetFromContentDB(); byte[]

MemoryStream: why convert to byte after readByte

£可爱£侵袭症+ 提交于 2019-12-01 14:07:07
问题 In this example from MS, you'll notice that after we read a byte from memory stream, it goes into an int which must then be converted to byte. It stikes me as strange that a function like .ReadByte() doesn't return a byte in the first place. Is there a reason why MS did it this way? // Read the remaining bytes, byte by byte. while(count < memStream.Length) { byteArray[count++] = Convert.ToByte(memStream.ReadByte()); } a thought occured to me. Perhaps this comes down to usage. Perhaps ReadByte

Create .wav from multiple sine waves and play all at once [closed]

北城以北 提交于 2019-12-01 13:32:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm wondering if there is a way to adapt the code shown here so that I can basically make an array of beeps and play them all at once. I tried making global MemoryStream and BinaryWriter to use, calculating everything ahead of time for the size but it was even slower than 1 beep at a time and didn't seem to work.

Saving as jpeg from memorystream in c#

倖福魔咒の 提交于 2019-12-01 09:02:08
I have a method as shown below to save image as jpeg. I want to save all the pictures with the same height and width without it getting distorted. How can I do that? Please help public void SaveFileOnDisk(MemoryStream ms, string FileName) { try { string appPath = HttpContext.Current.Request.ApplicationPath; string physicalPath = HttpContext.Current.Request.MapPath(appPath); string strpath = physicalPath + "\\Images"; string WorkingDirectory = strpath; System.Drawing.Image imgSave = System.Drawing.Image.FromStream(ms); Bitmap bmSave = new Bitmap(imgSave); Bitmap bmTemp = new Bitmap(bmSave);

Play videos from memory stream

混江龙づ霸主 提交于 2019-12-01 07:40:37
问题 Couldn't find any satisfying answer anywhere so far... I'm working on a C# WinForms .NET3.5 application that needs to load video files from a database BLOB and play it inside the application window. The database is a local file (no servers involved). I don't think that saving the file to the hard drive is a good solution since it might be time consuming, and I already have the file in a memory stream anyway. I need to be able to play as much types of video formats as possible (codecs?).

Saving as jpeg from memorystream in c#

﹥>﹥吖頭↗ 提交于 2019-12-01 06:53:31
问题 I have a method as shown below to save image as jpeg. I want to save all the pictures with the same height and width without it getting distorted. How can I do that? Please help public void SaveFileOnDisk(MemoryStream ms, string FileName) { try { string appPath = HttpContext.Current.Request.ApplicationPath; string physicalPath = HttpContext.Current.Request.MapPath(appPath); string strpath = physicalPath + "\\Images"; string WorkingDirectory = strpath; System.Drawing.Image imgSave = System

Convert a wav file to 8000Hz 16Bit Mono Wav

大兔子大兔子 提交于 2019-12-01 06:37:19
问题 I need to convert a wav file to 8000Hz 16Bit Mono Wav. I already have a code, which works well with NAudio library, but I want to use MemoryStream instead of temporary file. using System.IO; using NAudio.Wave; static void Main() { var input = File.ReadAllBytes("C:/input.wav"); var output = ConvertWavTo8000Hz16BitMonoWav(input); File.WriteAllBytes("C:/output.wav", output); } public static byte[] ConvertWavTo8000Hz16BitMonoWav(byte[] inArray) { using (var mem = new MemoryStream(inArray)) using

MemoryStream usage leads to out of memory exception

感情迁移 提交于 2019-12-01 04:09:23
I'am facing issues when using MemoryStream multiple times. Example: For Each XImage As XImage In pdfDocument.Pages(pageCount).Resources.Images Dim imageStream As New MemoryStream() XImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg) ' some further processing imageStream.Close() imageStream.Dispose() Next This piece of code cycles through images on a page of PDF file. The file may have up to cca 500 pages, lets say 5 images on each page. It leads to thousands of iterations. The issue is that the MemoryStream is not freed and it lead to Out of Memory exceptions. The XImage has