Sunday, March 15, 2009
Image Production on the fly graphics
Changes in web.config
<httpHandlers>
<add verb="*" path="myImage.jpg" type="ASPImagesOnTheFly.ImageHandler" />
</httpHandlers>
<handlers>
<add name="imageMaker" path="myImage.jpg" verb="*" type="ASPImagesOnTheFly.ImageHandler" requireAccess="None" preCondition="integratedMode" resourceType="Unspecified" />
</handlers>
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace ASPImagesOnTheFly
{
public class ImageHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
string s = context.Request.QueryString["item1"];
Bitmap bm = new Bitmap(800, 700);
Graphics g = Graphics.FromImage(bm);
Brush b = new LinearGradientBrush(new Point(1, 1), new Point(600, 600),
Color.White, Color.Red);
Point[] points = new Point[] {new Point (10,10), new Point(77,500), new Point(590, 100),
new Point(250,590), new Point(300,410)};
g.FillPolygon(b, points);
Font f = new Font("Arial", 24);
Brush sb = new SolidBrush(Color.White);
g.DrawString(s, f, sb, 400, 400);
context.Response.ContentType = "image/jpeg";
bm.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}
}
Subscribe to:
Comments (Atom)