--------Web.config----------------
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add verb="*" path="images/*.jpg" type="模块与处理程序.ImageDeal"/>
</httpHandlers>
</system.web>
</configuration>
-------------ImageDeal.cs类-------------------------
namespace 模块与处理程序
{
public class ImageDeal:IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
Image img = Image.FromFile(context.Request.PhysicalPath);
Graphics g = Graphics.FromImage(img);
g.DrawString("QQ", new Font("宋体", 20, FontStyle.Bold), Brushes.Red, 10, 10);
img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.Flush();
context.Response.End();
}
}
}
----------default2.aspx前台------------------------
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="sid" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="sid" HeaderText="sid" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:BoundField DataField="sname" HeaderText="sname" SortExpression="sname" />
<asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:ImageField DataImageUrlField="photo"
DataImageUrlFormatString="~/images/{0}" HeaderText="照片">
</asp:ImageField>
<asp:HyperLinkField DataNavigateUrlFields="sid,sname"
DataNavigateUrlFormatString="{0}/{1}/viewDetail.html" HeaderText="操作"
Text="查看详情" />
</Columns>
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
SelectCommand="SELECT [sid], [sname], [sex], [age], [photo] FROM [student]">
</asp:SqlDataSource>
</div>
</form>
</body>
-------------default3前台-----------------------
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" ImageUrl="http://localhost:1695/images/liubei.jpg" runat="server" />
</div>
</form>
</body>