Simpler way to create a C++ memorystream from (char*, size_t), without copying the data?

I’m assuming that your input data is binary (not text), and that you want to extract chunks of binary data from it. All without making a copy of your input data. You can combine boost::iostreams::basic_array_source and boost::iostreams::stream_buffer (from Boost.Iostreams) with boost::archive::binary_iarchive (from Boost.Serialization) to be able to use convenient extraction >> operators to read chunks … Read more

How to bind a MemoryStream to asp:image control?

Best bet is to create an HttpHandler that would return the image. Then bind the ImageUrl property on the asp:Image to the url of the HttpHandler. Here is some code. First create the HttpHandler: <%@ WebHandler Language=”C#” Class=”ImageHandler” %> using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Web; public class ImageHandler : IHttpHandler { public void … Read more

Image.FromStream() method returns Invalid Argument exception

Image.FromStream() expects a stream that contains ONLY one image! It resets the stream.Position to 0. I’ve you have a stream that contains multiple images or other stuff, you have to read your image data into a byte array and to initialize a MemoryStream with that: Image.FromStream(new MemoryStream(myImageByteArray)); The MemoryStream has to remain open as long … Read more

Serializing/deserializing with memory stream

This code works for me: public void Run() { Dog myDog = new Dog(); myDog.Name= “Foo”; myDog.Color = DogColor.Brown; System.Console.WriteLine(“{0}”, myDog.ToString()); MemoryStream stream = SerializeToStream(myDog); Dog newDog = (Dog)DeserializeFromStream(stream); System.Console.WriteLine(“{0}”, newDog.ToString()); } Where the types are like this: [Serializable] public enum DogColor { Brown, Black, Mottled } [Serializable] public class Dog { public String Name … Read more

Converting TMemoryStream to ‘String’ in Delphi 2009

The code you have is unnecessarily complex, even for older Delphi versions. Why should fetching the string version of a stream force the stream’s memory to be reallocated, after all? function MemoryStreamToString(M: TMemoryStream): string; begin SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char)); end; That works in all Delphi versions, not just Delphi 2009. It works when the … Read more