memorystream

MemoryStream disables reading when returned

a 夏天 提交于 2019-12-10 12:43:47
问题 In my program, I am basically reading in a file, doing some processing to it, and then passing it back to the main program as a memorystream, which will be handled by a streamreader. This will all be handled by a class beside my main. The problem is, when I return the memory stream from my method in another class, the "canread" variable is set to false, and thus causes the streamreader initialization to fail. Below is an example of the problem happening (though in here I'm writing to the

Sending image with byte array convertion, from java to c#

こ雲淡風輕ζ 提交于 2019-12-10 10:29:37
问题 I am trying to send a .jpg file which is on my android device to my server computer. To do this, I am converting the picture into a byte array by a java android application, and sending it as an argument to my server computer. I`m doing this by a web service call. The first function is edited: public static byte[] ImageConvertion(){ File inputFile = new File("/storage/emulated/0/IFSpictures/icon-si_strapclamp.jpg"); byte[] data; try{ FileInputStream input = new FileInputStream(inputFile);

want to re-use MemoryStream

牧云@^-^@ 提交于 2019-12-10 03:52:18
问题 My code uses MemoryStream to serialize/deserialize objects to/from the network. I would like to re-use a single MemoryStream in my class, rather than create a new one each time I need to send something over the wire. Does anyone know how to do this? Code snippet: // Serialize object to buffer public byte[] Serialize(object value) { if (value == null) return null; MemoryStream _memoryStream = new MemoryStream(); _memoryStream.Seek(0, 0); _bf.Serialize(_memoryStream, value); return

How can I read from memory just like from a file using wistream?

别等时光非礼了梦想. 提交于 2019-12-09 22:47:18
问题 In my previous question I asked how to read from a memory just as from a file. Because my whole file was in memory I wanted to read it similarly. I found answer to my question but actually I need to read lines as a wstring . With file I can do this: wifstream file; wstring line2; file.open("C:\\Users\\Mariusz\\Desktop\\zasoby.txt"); if(file.is_open()) { while(file.good()) { getline(file,line2); wcout << line2 << endl; } } file.close(); Even if the file is in ASCII. Right now I'm simply

C# Casting MemoryStream to FileStream

烂漫一生 提交于 2019-12-09 17:54:05
问题 My code is this: byte[] byteArray = Encoding.ASCII.GetBytes(someText); MemoryStream stream = new MemoryStream(byteArray); StreamReader reader = new StreamReader(stream); FileStream file = (FileStream)reader.BaseStream; Later I'm using file.Name. I'm getting an InvalidCastException: it displays follows Unable to cast object of type 'System.IO.MemoryStream' to type 'System.IO.FileStream'. I read somewhere that I should just change FileStream to Stream. Is there something else I should do? 回答1:

Read ionic Zip as Memory Stream C#

主宰稳场 提交于 2019-12-09 15:50:18
问题 I am using Ionic.Zip to extract ZipFile to memory stream with this method: private MemoryStream GetReplayZipMemoryStream() { MemoryStream zipMs = new MemoryStream(); using (ZipFile zip = ZipFile.Read(myFile.zip)) { foreach (ZipEntry zipEntry in zip) { if (zipEntry.FileName.StartsWith("Aligning") || zipEntry.FileName.StartsWith("Sensing")) { zipEntry.Extract(zipMs); } } } zipMs.Seek(0, SeekOrigin.Begin); return zipMs; } Once I am done extracting, I want to read the streams and get some of the

Size of bitmap byte[] differs from BMP memorystream size

我与影子孤独终老i 提交于 2019-12-09 03:56:29
问题 I´m trying to send a bitmap over a tcp/ip connection. So far my programm works as it should. But during debugging I discovered a strange value of my bitmap byte[]. I open a 24bit bitmap and convert it to 16bit. The bitmap is 800x600 so the byte[] length should be 800*800*2Byte = 960000Byte... But my array is 960054... Where do the extra Bytes come from?? Console.WriteLine("Bitmap auf 16Bit anpassen...\n"); Rectangle r = new Rectangle(0,0,bitmap_o.Width, bitmap_o.Height); Bitmap bitmap_n =

How can I clone MemoryStream object?

假装没事ソ 提交于 2019-12-08 19:28:21
问题 I have a MemoryStream object which is passed by Stream type parameter ( Stream is abstract class in C#). I want to clone him and to create another MemoryStream object a side with current position of the original and to create also a new XMLReader out of it, so I will be able to read its content. This is what I did, and it's not working (debugging the line marked with //* -> newReader has got {None} value) Assumption : you are inside a method and have Stream currentStream reference. var x =

how to convert created excel file using closed xml into bytes format

十年热恋 提交于 2019-12-08 08:59:25
问题 Hi I am using closedxML DLL for exporting to excel i have static method like this below public static void WriteToExcel(string fileName, List<CP> pages) { var wb = new XLWorkbook(); byte[] file; var ws = wb.Worksheets.Add("CPs"); WriteCostHeader(ws); ////write all the header columns //for (int i = 0; i < pages.Count; i++) int iRow = 2; foreach(var page in pages) { WriteCostPage(ws, page, iRow++); WriteCostItemHead(ws, iRow++); foreach(var item in page.Items) { WriteCostItem(ws, item, iRow++);

MemoryStream.Position or MemoryStream.Seek does not work (Silverlight)

自作多情 提交于 2019-12-08 08:15:22
问题 I have a memorystream in a silverlight app. I have to copy this memorystream to a filestream object. If I call: memoryStream.Position = 0; memoryStream.Seek(0,SeekOrigin.Begin); It does not work, I debug the application, check the properties of the memorystream, and the position still points to the end of the file. Any clues? 回答1: Is it possible that another of your properties is being triggered in the debugger, and reading through the stream? Rather than using the debugger, what happens if