memorystream

convert string to memory stream - Memory stream is not expandable?

折月煮酒 提交于 2019-12-03 04:15:59
i was trying to write a string to a memory stream, but failed with the error message: Memory stream is not expandable. the line of code that produces this problem: context.Response.Filter = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(myPage)); anyone have a workaround/fix for that? stacktrace: [NotSupportedException: Memory stream is not expandable.] System.IO.MemoryStream.set_Capacity(Int32 value) +9385744 System.IO.MemoryStream.EnsureCapacity(Int32 value) +50 System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) +265 System.Web.HttpWriter.FilterIntegrated

Do I need to do StreamWriter.flush()?

馋奶兔 提交于 2019-12-03 01:12:25
Suppose this C# code: using (MemoryStream stream = new MemoryStream()) { StreamWriter normalWriter = new StreamWriter(stream); BinaryWriter binaryWriter = new BinaryWriter(stream); foreach(...) { binaryWriter.Write(number); normalWriter.WriteLine(name); //<~~ easier to reader afterward. } return MemoryStream.ToArray(); } My questions are: Do I need to use flush inside the loop to preserve order? Is returning MemoryStream.ToArray() legal? I using the using -block as a convention, I'm afraid it will mess things up. Scratch the previous answer - I hadn't noticed that you were using two wrappers

Why does C# memory stream reserve so much memory?

瘦欲@ 提交于 2019-12-03 01:08:13
Our software is decompressing certain byte data through a GZipStream , which reads data from a MemoryStream . These data are decompressed in blocks of 4KB and written into another MemoryStream . We've realized that the memory the process allocates is much higher than the actual decompressed data. Example: A compressed byte array with 2,425,536 bytes gets decompressed to 23,050,718 bytes. The memory profiler we use shows that the Method MemoryStream.set_Capacity(Int32 value) allocated 67,104,936 bytes. That's a factor of 2.9 between reserved and actually written memory. Note: MemoryStream.set

No imaging component suitable to complete the operation was found WPF vb.net

痞子三分冷 提交于 2019-12-02 22:39:19
问题 I inserted an image into a .mdb database with this code from my WPF app : Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & GetCurrentDirectory() & "\Data\rctts.mdb;Jet OLEDB:Database Password=arn33423342;") con.Open() Dim cmd As New OleDbCommand("Insert into recents(Uname,Pic,Email)values(@uname,@pic,@email)", con) image1.Source = New BitmapImage(New Uri("D:\logo.png")) Dim buffer As Byte() Dim bitmap = TryCast(image1.Source, BitmapSource) Dim encoder = New

No imaging component suitable to complete the operation was found WPF vb.net

被刻印的时光 ゝ 提交于 2019-12-02 13:20:18
I inserted an image into a .mdb database with this code from my WPF app : Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & GetCurrentDirectory() & "\Data\rctts.mdb;Jet OLEDB:Database Password=arn33423342;") con.Open() Dim cmd As New OleDbCommand("Insert into recents(Uname,Pic,Email)values(@uname,@pic,@email)", con) image1.Source = New BitmapImage(New Uri("D:\logo.png")) Dim buffer As Byte() Dim bitmap = TryCast(image1.Source, BitmapSource) Dim encoder = New PngBitmapEncoder() encoder.Frames.Add(BitmapFrame.Create(bitmap)) Using stream = New MemoryStream()

Play video file from a memory stream

五迷三道 提交于 2019-12-02 10:06:53
Just curious to see if this is possible. I have a windows application that reads all the bytes from a .avi file situated on my pc and then stores it in a byte[]. So now I have the avi file in memory, and I want to load it into some sort of a video player control, directly from memory. I've tried using the wmplayer control, apparently this is not possible. I've read suggestion about using the DirectShow and VLC plugins, but I have no idea where to even start using those two and I haven't seen any sample code of this being down. Anybody have any ideas to elaborate on the mentioned plugins, or

Read a stored PDF from memory stream

断了今生、忘了曾经 提交于 2019-12-01 20:13:25
问题 I'm working on a database project using C# and SQLServer 2012. In one of my forms I have a PDF file with some other information that is stored in a table. This is working successfully, but when I want to retrieve the stored information I have a problem with displaying the PDF file, because I can't display it and I don't know how to display it. I read some articles that said it can not be displayed with Adobe PDF viewer from a memory stream, is there any way to that? This is my code for

Read a stored PDF from memory stream

一笑奈何 提交于 2019-12-01 19:49:17
I'm working on a database project using C# and SQLServer 2012. In one of my forms I have a PDF file with some other information that is stored in a table. This is working successfully, but when I want to retrieve the stored information I have a problem with displaying the PDF file, because I can't display it and I don't know how to display it. I read some articles that said it can not be displayed with Adobe PDF viewer from a memory stream, is there any way to that? This is my code for retrieving the data from the database: sql_com.CommandText = "select * from incoming_boks_tbl where [incoming

Serializing a memorystream object to string

六眼飞鱼酱① 提交于 2019-12-01 16:06:14
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[] byteArray = Encoding.ASCII.GetBytes(content); MemoryStream ms = new MemoryStream(byteArray); byte[] outBuf = ms

Why do these two files hash to the same value when I use MemoryStream?

隐身守侯 提交于 2019-12-01 16:03:39
问题 I'm writing a c# routine that creates hashes from jpg files. If I pass in a byte array to my SHA512 object then I get the expected behavior, however, if I pass in a memory stream the two files always hash to the same value. Example 1: SHA512 mySHA512 = SHA512.Create(); Image img1 = Image.FromFile(@"d:\img1.jpg"); Image img2 = Image.FromFile(@"d:\img2.jpg"); MemoryStream ms1 = new MemoryStream(); MemoryStream ms2 = new MemoryStream(); img1.Save(ms1, ImageFormat.Jpeg); byte[] buf1 = ms1