文件1:showimage.aspx.cs
![](/icons/66798namespace.gif)
ImageResizing {
public
![](/icons/66798class.gif)
MainDisplay :
![](/icons/66798System.gif)
.Web.UI.Page {
public void Page_Load(
![](/icons/66798System.gif)
.Object sender,
![](/icons/66798System.gif)
.EventArgs e) {
try {
![](/icons/66798System.gif)
.Int32 _ImgID =
![](/icons/66798System.gif)
.Convert.ToInt32(Request.QueryString[\"ImgID\"]);
![](/icons/66798System.gif)
.Int32 _height =
![](/icons/66798System.gif)
.Convert.ToInt32(Request.QueryString[\"height\"]);
![](/icons/66798System.gif)
.Int32 _width =
![](/icons/66798System.gif)
.Convert.ToInt32(Request.QueryString[\"width\"]);
![](/icons/66798System.gif)
.Data.SqlClient.SqlConnection Con =
![](/icons/66798System.gif)
.Data.SqlClient.SqlConnection( \"server=localhost;database=northwind;trusted_connection=true\" );
![](/icons/66798System.gif)
.String SqlCmd = \"SELECT * FROM Images WHERE ImageID = @ImageID\";
![](/icons/66798System.gif)
.Data.SqlClient.SqlCommand SqlCmdObj =
![](/icons/66798System.gif)
.Data.SqlClient.SqlCommand( SqlCmd, Con );
SqlCmdObj.Parameters.Add(\"@ImageID\",
![](/icons/66798System.gif)
.Data.SqlDbType.Int).Value = _ImgID;
Con.Open
![](/icons/66798kh.gif)
;
![](/icons/66798System.gif)
.Data.SqlClient.SqlDataReader SqlReader = SqlCmdObj.ExecuteReader
![](/icons/66798kh.gif)
;
SqlReader.Read
![](/icons/66798kh.gif)
;
![](/icons/66798System.gif)
.Web.HttpContext.Current.Response.ContentType = \"image/pjpeg\";
![](/icons/66798System.gif)
.Drawing.Image _image =
![](/icons/66798System.gif)
.Drawing.Image.FromStream(
![](/icons/66798System.gif)
.IO.MemoryStream( (
![](/icons/66798byte.gif)
![](/icons/66798zhk2.gif)
)SqlReader[\"Image\"] ) );
![](/icons/66798System.gif)
.Drawing.Image _
![](/icons/66798new.gif)
image = _image.GetThumbnailImage( _width, _height, null,
![](/icons/66798System.gif)
.IntPtr
![](/icons/66798kh.gif)
);
_
![](/icons/66798new.gif)
image.Save(
![](/icons/66798System.gif)
.Web.HttpContext.Current.Response.OutputStream,
![](/icons/66798System.gif)
.Drawing.Imaging.ImageFormat.Jpeg );
} catch (
![](/icons/66798System.gif)
.Exception Ex) {
![](/icons/66798System.gif)
.Web.HttpContext.Current.Trace.Write(Ex.Message.
![](/icons/66798ToString.gif)
![](/icons/66798kh.gif)
);
}
}
}
}
文件2:显示图片的用
![](/icons/66798dou.gif)
把query
![](/icons/66798string.gif)
传入
<html>
<body>
<img src=\"showimage.aspx?ImgID=202&height=150&width=150\">
</body>
</html>