国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

如何把存儲在數據庫中的圖片根據自己的需要的大小顯示出來

2019-11-18 20:28:04
字體:
來源:轉載
供稿:網友
文件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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 城步| 军事| 丹江口市| 克什克腾旗| 上虞市| 全南县| 庆安县| 东港市| 思茅市| 治多县| 临朐县| 福安市| 咸丰县| 苍山县| 名山县| 青州市| 游戏| 凤庆县| 古交市| 西宁市| 张家港市| 南宁市| 关岭| 建湖县| 衡山县| 浠水县| 汉寿县| 习水县| 西城区| 台州市| 娱乐| 田阳县| 虞城县| 斗六市| 犍为县| 柳林县| 灵台县| 澳门| 常德市| 宜阳县| 丽江市|