欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

文件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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何正确显示数据库中的图片
分享到: 更多 (0)

相关推荐

  • 暂无文章