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

ASP
ASP技巧研究:ASP Error对象的相关知识
ASP模拟MVC模型的编程方式
学ASP应该注意ASP程序书写的规范
用文本+ASP打造新闻发布系统
ASP Session对象的集合以及属性方法事件
ASP防止盗链或防止下载的方法
ASP开发中存储过程应用详解
ASP脚本语言的19个基本技巧使用
ASP中使用Form和QueryString集合
在ASP中访问和更新Cookies集合
在ASP中操作HTTP报头方法分析
建立三层结构的ASP应用程序
ASP动态网页编程的19个基本技巧
ASP教程:制作登陆验证页面程序
asp正则表达式详细说明
使用ASP订制自己的XML文件读写方法
ASP中的Debug类--VBScript
Asp中如何设计跨越域的Cookie
DHTML+XML+ASP+CSS的树形目录
实例一则 ASP程序中输出Excel文件

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 76 ::
收藏到网摘: 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>