日期:2013-10-09  浏览次数:20830 次

具体给个例子就清楚啦。。
如下:
System.Web.HttpPostedFile UpFile = UpMhtFile.PostedFile;

System.IO.Stream StreamObject = UpFile.InputStream;

System.IO.FileStream myStream = new System.IO.FileStream(UpFile.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);



System.Drawing.Image.GetThumbnailImageAbort myCallback =

new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);



System.Drawing.Image img1 = System.Drawing.Image.FromStream(StreamObject);



System.Drawing.Image timg = img1.GetThumbnailImage(100,100,myCallback,System.IntPtr.Zero);

timg.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);


上例中UpMhtFile是一个upfile WebControl,上述情况将上传的图片转换成流,然后生成缩略图后直接保存在输出流中,一般用于从数据库中读出流后生成图片浏览。