仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3460|回复: 19
打印 上一主题 下一主题

[学习教程] ASP编程:若何准确显示数据库中的图片

[复制链接]
不帅 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-16 00:25:34 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用filesystemobject,可以对服务器上的文件进行操作,浏览、复制、移动、删除等。有ado的支持,asp对数据库的操作非常得心应手。你甚至可以像使用本地数据库那样,管理远程主机上的数据库,对表格、记录进行各种操作。数据|数据库|显示   文件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>

</p>  asp可以轻松地实现对页面内容的动态控制,根据不同的浏览者,显示不同的页面内容。而浏览者一点觉察不出来,就像为他专门制作的页面一样。使用各种各样的组件,asp可以完成无比强大的功能。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-9 14:16

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表