public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
public static extern void CloseMemory(FIMEMORY stream);
public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes);
public static extern int TellMemory(FIMEMORY stream);
public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin);
public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags);
public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size);
/// <summary> /// Loads a FreeImage multi-paged bitmap from a stream and returns the /// FreeImage memory stream used as temporary buffer. /// The bitmap can not be modified by calling /// <see cref="FreeImage.AppendPage(FIMULTIBITMAP,FIBITMAP)"/>, /// <see cref="FreeImage.InsertPage(FIMULTIBITMAP,Int32,FIBITMAP)"/>, /// <see cref="FreeImage.MovePage(FIMULTIBITMAP,Int32,Int32)"/> or /// <see cref="FreeImage.DeletePage(FIMULTIBITMAP,Int32)"/>. /// </summary> /// <param name="stream">The stream to read from.</param> /// <param name="format">Format of the image.</param> /// <param name="flags">Flags to enable or disable plugin-features.</param> /// <param name="memory">The temporary memory buffer used to load the bitmap.</param> /// <returns>Handle to a FreeImage multi-paged bitmap.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="stream"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="stream"/> can not read.</exception> public static FIMULTIBITMAP LoadMultiBitmapFromStream( Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags, out FIMEMORY memory) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanRead) { throw new ArgumentException("stream"); } const int blockSize = 1024; int bytesRead; byte[] buffer = new byte[blockSize]; stream = stream.CanSeek ? stream : new StreamWrapper(stream, true); memory = OpenMemory(IntPtr.Zero, 0); do { bytesRead = stream.Read(buffer, 0, blockSize); WriteMemory(buffer, (uint)blockSize, (uint)1, memory); } while (bytesRead == blockSize); return LoadMultiBitmapFromMemory(format, memory, flags); }