Library tutorials & articles
ASP.NET and GDI+
- In the beginning
- The image generator start part 1
- The image generator part 2
- Finishing Up
In the beginning
So you want to know how to generate an image with an ASP page on the fly? Well there is a few ways to do it, such as flash etc, but with Microsoft and GDI+ the task is made a lot easier. This tutorial just covers the basics, but from it you can always move on and experiment with GDI+ (and intellisense) :)
Well, lets start with the calling page default.aspx (or whatever you would like to call it):
I usually like to draw all my controls to a table using code, there are other ways to do it, but I like doing it this way:
- Add a
TextBoxto thedefault.aspxpage calling it whatever you like (for the tutorial we'll call ittxtWord) - Add a
CommandButtonto the page and call it whatever you like (just to submit the form) - Add a server side
Tablecontrol (call it what you want I'll just call itimageTable) - In the codebehind page (
.aspx.vb) add the following code, or similar to thePage_LoadprocedurePrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' #Check if the page is posted
If Page.IsPostBack Then
Dim m_sWord As String
m_sWord = Request("txtWord")
' #Check if txtWord has a value
If Not m_sWord = "" Then
GenImage(m_sWord)
Else
Dim tRow As New TableRow
Dim tCell As New TableCell
tCell.Controls.Add(New LiteralControl("Error getting the word you posted"))
tRow.Controls.Add(tCell)
imageTable.Controls.Add(tCell)
End If
End If
End Sub - Add a function called
GenImage:Public Function GenImage(ByVal sWord As String)
'#Create the row and cell to hold the image in
Dim tRow As New TableRow
Dim tCell As New TableCell
tCell.Controls.Add(New LiteralControl("<img src='img_gen.aspx?w=' & sWord & '>"))
tRow.Controls.Add(tCell)
imageTable.Controls.Add(tRow)
End Function
So now you have a page that accepts a word posted to it by itself, and calls a aspx page as an image source. Now that was easy, next the fun part ... drawing :).
Related articles
Related discussion
-
increase maxRequestLength in httpRuntime of Web.Config
by bussureddy82 (0 replies)
-
Gizmox Announces release of Visual WebGui SDK version 6.2.2
by Visual WebGui (0 replies)
-
Error 4 Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
by lbargers (3 replies)
-
How to receive data in web server sending from GPRS modem
by AshokSingh (1 replies)
-
Working with frames in c# .net
by pulak2008 (0 replies)
Related podcasts
-
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
.net developer
in Rijswijk (€2K-€4K per annum)
Events coming up
-
Dec
9
Internet Information Services 7.0 for ASP.Net Developers
Glasgow, United Kingdom
One of the biggest and best new features of Windows Server 2008 and Windows Vista is Internet Information Server 7.0. IIS 7.0 is the latest and most significant release of Microsoft's Web Server. With this release comes a new extensibility model which gives developers more options than ever before, more diagnostic tools with which developers can debug and locate issues. During the session Andrew will investigate the new architecture, look at extending, configuring and developing for IIS7, ta...
This thread is for discussions of ASP.NET and GDI+.