Building a Page Counter (Image) Using JScript.Net
page 4 of 6
by Devarticles.com
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28310/ 78

The JScript.Net Code, Part 2

Now we want to replace the text counter with an image that we will create on the fly. Add the following code to counter.aspx before the "Response.Write(getCounter());" line:

[code="JScript"]

function drawCounter()
{
var height:int=20;
var width:int=60;

var bmp:Bitmap = new Bitmap(width, height);
var img:Graphics = Graphics.FromImage(bmp);

var white:SolidBrush = new SolidBrush(Color.White);
var black:SolidBrush = new SolidBrush(Color.Black);

var CurrentCounter:String = getCounter();

var CounterFont:Font = new Font("Arial", 8, FontStyle.Bold);
var Text:SizeF = img.MeasureString(CurrentCounter,CounterFont);

img.FillRectangle(black, 0, 0, width, height);
img.DrawString(CurrentCounter, CounterFont, white ,(bmp.Width)-((Text.Width)+5),3);

bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

img.Dispose();
bmp.Dispose();
}

[/code]


View Entire Article

User Comments

Title: Firefox :s   
Name: Remi
Date: 2007-04-07 9:04:44 AM
Comment:
Thnx!
Works great in IE! Only Firefox has some problems displaying the image. It just shows a range of weird characters :s.
Title: SPA   
Name: dheeraj Ahuja
Date: 2005-10-28 3:07:28 AM
Comment:
this is gud article and it helped me alot
now wht i want is to call a server side from client routine with refering any "src",
is there any way

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-18 11:47:16 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search