protected void Page_Load(object sender, EventArgs e) { string counterid = Request["id"]; _srv = ServiceFactory.GetCounterService(); if (Application["Counter_" + counterid] == null) { _counter = _srv.CounterSelect( 5 ); Application["Counter_" + counterid] = _counter.Count; } int value = Convert.ToInt32( Application["Counter_" + counterid]); if (Session["CounterTemp_" + counterid] == null) { if(_counter == null) _counter = _srv.CounterSelect( 5 ); value++; _counter.Count = value; // Save counter to an application var (the locks are there to make sure noone else changes it at the same time) Application.Lock(); Application["Counter_" + counterid] = value.ToString(); Application.UnLock(); // Save counter to a text file _srv.CounterUpdate( _counter ); // Set a session variable so this counter doesn//t fire again in the current session Session.Add("CounterTemp_" + counterid, "True"); } // ***** CREATE OUTPUT GRAPHIC FOR THE COUNTER ***** // Load digits graphic (must be in 0 through 9 format in graphic w/ all digits of set width) System.Drawing.Image i = System.Drawing.Image.FromFile(Server.MapPath((Request.QueryString["src"]))); // Get digit dynamics from the graphic int dgwidth = i.Width/10; int dgheight = i.Height; // Get number of digits to display in the output graphic int digits = Convert.ToInt32(Request["digits"]); // Create output object Bitmap imgOutput = new Bitmap(dgwidth*digits, dgheight, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(imgOutput); int j; int dg; string srt = ("00000000000000" + value.ToString()); srt = srt.Substring( srt.Length - digits, digits ); for (j = 0; j < digits; j++) { // Extract digit from value //dg = Convert.ToInt32(Math.Truncate((double)(value/(10 ^ (digits - j - 1)))) - Math.Truncate((double)(value/(10 ^ (digits - j))))*10); dg = Convert.ToInt32( srt.Substring( j, 1 ) ); // Add digit to the output graphic g.DrawImage(i, new Rectangle(j*dgwidth, 0, dgwidth, dgheight), new Rectangle (dg*dgwidth, 0, dgwidth, dgheight), GraphicsUnit.Pixel); } // Set the content type and return output image Response.ContentType = "image/jpeg"; imgOutput.Save(Response.OutputStream, ImageFormat.Jpeg); // Clean up g.Dispose(); imgOutput.Dispose(); }