国产探花免费观看_亚洲丰满少妇自慰呻吟_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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仁化县| 嫩江县| 娱乐| 西青区| 南安市| 万源市| 环江| 东源县| 岱山县| 涞源县| 汉川市| 陇西县| 容城县| 渝北区| 兴义市| 柘荣县| 平湖市| 武安市| 乐至县| 仁布县| 伊金霍洛旗| 古浪县| 穆棱市| 伊宁县| 房产| 南安市| 华安县| 五家渠市| 麻栗坡县| 砀山县| 定远县| 台北县| 大厂| 衡南县| 金华市| 宽城| 西藏| 阿鲁科尔沁旗| 镇康县| 彭水| 马尔康县|