当前位置: 首页 > 图文教程 > 网络编程 > ASP > 如何正确显示数据库中的图片

ASP
asp下用fso生成js文件的代码
非常好用的asp备份,还原SQL数据库的代码
asp从字符串里截取N个带HTML的字符的函数
asp下Response.Buffer提速
ASP,vbs正则轮翻在文章段落后加上网址等内容
ASP为字符串中的网址自动加上链接
ASP vbs 代码大小写规范
ASP实现智能搜索实现代码
asp结合fso实现文件或文件夹创建删除等操作的函数
asp下对POST提交数据限制的解决方法
asp+Access通用的自动替换数据库中的字符串
asp alexa查询小偷程序
迅雷API接口_通过脚本调用迅雷自动下载资源
asp下的一个检测链接是否正常的函数
asp一句话木马原理分析
asp生成不需要数据库的中奖码
asp遍历目录及子目录的函数
asp数据库连接rs("user.id")
vbs或asp采集文章时网页编码问题
新手asp编程的基本法则与常见错误注意事项

ASP 中的 如何正确显示数据库中的图片


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 140 ::
收藏到网摘: n/a

文件1:showimage.aspx.cs


namespace ImageResizing {

public class MainDisplay : System.Web.UI.Page {

public void Page_Load(System.Object sender, System.EventArgs e) {

try {

System.Int32 _ImgID = System.Convert.ToInt32(Request.QueryString["ImgID"]);

System.Int32 _height = System.Convert.ToInt32(Request.QueryString["height"]);

System.Int32 _width = System.Convert.ToInt32(Request.QueryString["width"]);

System.Data.SqlClient.SqlConnection Con = new System.Data.SqlClient.SqlConnection( "server=localhost;database=northwind;trusted_connection=true" );

System.String SqlCmd = "SELECT * FROM Images WHERE ImageID = @ImageID";

System.Data.SqlClient.SqlCommand SqlCmdObj = new System.Data.SqlClient.SqlCommand( SqlCmd, Con );

SqlCmdObj.Parameters.Add("@ImageID", System.Data.SqlDbType.Int).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.FromStream( new System.IO.MemoryStream( (byte[])SqlReader["Image"] ) );

System.Drawing.Image _newimage = _image.GetThumbnailImage( _width, _height, null, new System.IntPtr());

_newimage.Save( System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg );

} catch (System.Exception Ex) {

System.Web.HttpContext.Current.Trace.Write(Ex.Message.ToString());

}

}

}

}


文件2:显示图片之用,把querystring传入
<html>
<body>

<img src="showimage.aspx?ImgID=202&height=150&width=150">
</body>
</html>