Source Code
The following C# source code shows the code-behind of the validation part.
// Define the page content type
Response.ContentType = "image/jpeg";
Bitmap bitmap;
Graphics g;
// initialize the blank bitmap
bitmap = new Bitmap(240,48);
g = Graphics.FromImage(bitmap);
HatchBrush hb = new HatchBrush(HatchStyle.DottedGrid,Color.Black,Color.White);
g.FillRectangle(hb,0,0,240,48);
// generate a random number
int num=0;
Random rand = new Random();
while (num<10000)
{
num = rand.Next(99999);
}
// initialize the CoolWatermark writer and assign the properties
angGoGo.CoolWatermark.Writer writer = new Writer((System.Drawing.Image)bitmap);
writer.PositionStyle = PositionStyle.MiddleCenter;
writer.Shadow = new Shadow(Color.LightGray,3,3);
writer.FontStyle = FontStyle.Bold;
writer.FontSize = 32;
writer.FontFamily = new FontFamily("Arial");
writer.Colors = new Color[]{Color.White};
writer.Border = new Border(Pens.Black);
bitmap = new Bitmap(writer.WriteText(num.ToString()));
writer.Dispose();
// write to webpage
MemoryStream oStream = new MemoryStream();
bitmap.Save(oStream,System.Drawing.Imaging.ImageFormat.Jpeg);
Response.BinaryWrite(oStream.ToArray());
bitmap.Dispose();
g.Dispose();
Response.End();
|