|
2. Graphics created via an HTTP
handler
On August 2002's MSDN magazine, Jeff
Prosise shows us how to use HTTP handlers to generate dynamic images in his
column "Wicked Code - Code your way to ASP.NET excellence". 1 line of
code on this page
Chart.ImageUrl
= String.Format("HTTPHandlers\PieChart.ashx?q1= {0}&q2= {1}&q3=
{2}&q4= {3}" + _ "&width= 256&height= 224", Q1.Text, Q3.Text,
Q3.Text, Q4.Text)
and
a few more lines of code in the implementation of the
ProcessRequest method of the HTTP handler class inside the
PieChart.ashx file named PieChartGenerator that inherits from IHttpHandler and,
Technically, an IHttpAsyncHandler class
can be associated with a file name extension or a particular URL by a
configuration file, in the <httpHandlers> section. The ASP.NET
infrastructure will then instantiate and call the handler when the
corresponding request is received. Alternatively, the handler can be defined in
an .ashx file and when the corresponding request is received for the .ashx
file, the hander will be executed. The example uses the later via a C# program.
It is invoked by the on_click event of the ShowChart button by
setting the image's imageURL property to the it and passing the values
entered on the textboxes for each quarter.
3. Creating your own bitmap.
ltImage.Text
= String.Format("<img
src='DrawString.aspx?Text={0}&Font={1}&Size={2}&Style={3}&Color={4}BackColor={5}&StringFormat={6}'>",
strText, strFontName, intFontSize, _ CType(fs, Integer), _
ddlTextColor.SelectedItem.Text, _ ddlBackColor.SelectedItem.Text, _
CType(sfmtFlags, Integer))
On the April 2003 issue of the
asp.netPRO magazine, Ken Getz shows us how to generate graphics with GDI+.
Once the bitmap image is created and
displayed on on this page, you can save it by right clicking on it
and choosing Save Picture As.
|