Search code examples
c#.netxnaclone

How can I clone FileStream type?


How can I clone FileStream type?

The problem is that I using MagickNet.Image(inputStream) to get the image distentions before saving it, but it seems to closing the inputStream.

So, I can send a clone of inputStream to the function, so the function cannot edit the real inputStream object?

This is my function:

public Picture GetPictureDimension(Stream inputStream, Picture picture)
{
    var img = new MagickNet.Image(inputStream);

    picture.Width = img.Columns;
    picture.Height = img.Rows;

    return picture;
}

Solution

  • You could just re-open the file? But to keep a single Stream without it getting closed, you could try NonClosingStreamWrapper in MiscUtil. Just be sure to reset the Position if appropriate.