This code returns a thumbnail of an image loaded from a byte array. I'm trying to understand why the author is using 4 memory streams and if there is a simple way of rewriting this or if it is okay the way it is.
public Image GetThumbnail(int height, int width)
{
//load the image from a byte array (imageData)
using (MemoryStream mem = new MemoryStream(this.imageData))
{
// Create a Thumbnail from the image
using (Image thumbPhoto = Image.FromStream(mem,
true).GetThumbnailImage(height, width, null,
new System.IntPtr()))
{
// Convert the Image object to a byte array
using (MemoryStream ms = new MemoryStream())
{
thumbPhoto.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
using (MemoryStream m = new MemoryStream(ms.ToArray()))
{
return Image.FromStream(m, true);
}
}
}
}
}