日期:2014-05-17 浏览次数:20585 次
<img src="smailImage.aspx">
smailImage.aspx 输出
protected void Page_Load(object sender, EventArgs e) { Response.ClearContent(); Response.ContentType = "images/jpeg"; Response.BinaryWrite(System.IO.File.ReadAllBytes(Server.MapPath("~/aaaa.jpg"))); Response.End(); }
------解决方案--------------------
或者显示指定文件的缩略图
protected void Page_Load(object sender, EventArgs e) { Response.ClearContent(); Response.ContentType = "images/jpg"; String file = Server.MapPath("~/aaaa.jpg"); //显示aaaa.jpg的缩略图 System.Drawing.Image image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(file))); int newWidth = 100, newHeight = 100; if ((decimal)image.Width / image.Height > (decimal)newWidth / newHeight) { newHeight = Convert.ToInt32((decimal)image.Height * newWidth / image.Width); } else if ((decimal)image.Width / image.Height < (decimal)newWidth / newHeight) { newWidth = Convert.ToInt32((decimal)image.Width * newHeight / image.Height); } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newWidth, newHeight); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, newWidth, newHeight); g.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel); bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); bmp.Dispose(); image.Dispose(); Response.End(); }
------解决方案--------------------