此代碼返回從字節數組加載的圖像的縮略圖。我試圖理解爲什麼作者正在使用4個內存流,以及是否有一種簡單的重寫方式,或者它是否正確。如何簡化此MemoryStream碼
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);
}
}
}
}
}
這樣做了。謝謝 – 2009-10-23 09:57:14