文件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>
相关链接:http://www.aspnextgen.com/tutorials.aspx?tutorialid=176
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器