This is what I'm using
<%@ WebHandler Language="C#" Class="GenericHandler1" %>
using System;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class GenericHandler1 : IHttpHandler {
public void ProcessRequest (HttpContext context) {
if (context.Request.QueryString.Keys.Count == 1)
{
try
{
int x, y;
y = Convert.ToInt32(context.Request.QueryString.Keys[0].Split('x')[0]);
x = Convert.ToInt32(context.Request.QueryString.Keys[0].Split('x')[1]);
MemoryStream mem = new MemoryStream();
Bitmap pic = new Bitmap(y, x);
Graphics g = Graphics.FromImage(pic);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(Image.FromFile(context.Server.MapPath(/SiteFiles/1000/oakwood2.png)), 0, 0, y, x);
context.Response.ContentType = "image/jpg";
pic.Save(mem, ImageFormat.Jpeg);
mem.WriteTo(context.Response.OutputStream);
pic.Dispose();
}
catch (Exception ex)
{
context.Response.Write(ex.ToString());
}
}
else context.Response.Redirect("~/");
}
public bool IsReusable {
get {
return false;
}
}
This is the error I get when trying to visit http://test.absolutepigskin.com/bg.ashx?800x600=1
Server Error in '/' Application.
Compilation Error
Description: An
error occurred during the compilation of a resource required to service
this request. Please review the following specific error details and
modify your source code appropriately.
Compiler Error Message: CS1525: Invalid expression term '/'
Source Error:
|
Line 22: Graphics g = Graphics.FromImage(pic); Line 23: g.SmoothingMode = SmoothingMode.AntiAlias; Line 24: g.DrawImage(Image.FromFile(context.Server.MapPath(/SiteFiles/1000/oakwood2.png)), 0, 0, y, x); Line 25: context.Response.ContentType = "image/jpg"; Line 26: pic.Save(mem, ImageFormat.Jpeg);
|
Source File: c:\HostingSpaces\tloker\test.absolutepigskin.com\wwwroot\bg.ashx
Line: 24