如何正确显示数据库中的图片
2010-8-17编辑:feimeimei
文件1:showimage.aspx.cs
namespace ImageResizing
public class MainDisplay : System.Web.UI.Page
public void Page_Load
try
System.Int32 _ImgID = System.Convert.ToInt32;
System.Int32 _height = System.Convert.ToInt32;
System.Int32 _width = System.Convert.ToInt32;
System.Data.SqlClient.SqlConnection Con = new System.Data.SqlClient.SqlConnection;
System.String SqlCmd = "SELECT * FROM Images WHERE ImageID = @ImageID";
System.Data.SqlClient.SqlCommand SqlCmdObj = new System.Data.SqlClient.SqlCommand;
SqlCmdObj.Parameters.Add.Value = _ImgID;
Con.Open;
System.Data.SqlClient.SqlDataReader SqlReader = SqlCmdObj.ExecuteReader;
SqlReader.Read;
System.Web.HttpContext.Current.Response.ContentType = "image/pjpeg";
System.Drawing.Image _image = System.Drawing.Image.FromStreamSqlReader["Image"] ) );
System.Drawing.Image _newimage = _image.GetThumbnailImage);
_newimage.Save;
catch
System.Web.HttpContext.Current.Trace.Write);
文件2:显示图片之用,把querystring传入
html
body
img /body
/html