示例代码:
复制代码 代码示例:
HttpRequest request = context.Request;
HttpServerUtility server = context.Server;
string Water =server.MapPath("~/vener.png");
HttpResponse response = context.Response;
string s = request.PhysicalPath;
response.ContentType = "Images/jpeg";
if (File.Exists(s) && request.UrlReferrer!=null&& request.UrlReferrer.ToString() == "http://localhost/")
{
Image image = Image.FromFile(s);
Image wimage =Image.FromFile(Water);
Graphics gs = Graphics.FromImage(image);
gs.DrawImage(wimage,new Rectangle(image.Width-wimage.Width,image.Height-wimage.Height,wimage.Width,wimage.Height));
gs.Dispose();
image.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
Image image = Image.FromFile(Water);
image.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
}
webconfig配置文件
复制代码 代码示例:
<system.web>
<httpHandlers>
<add path="Images/*.JPG" type="MyHttpHandler" verb="*" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="Handler" path="Images/*.jpg" verb="*" type="MyHttpHandler" resourceType="Unspecified" requireAccess="None" preCondition="integratedMode" />
</handlers>
</system.webServer>