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
-
Profile Class does not work after Translation
by converter2009 (1 replies)
-
what is the SQL Server Provider
by hayperaktib (1 replies)
-
Very Urgent regarding deleting the images from a folder
by Nanosteps (6 replies)
-
Java Script, File uploading on ftp server using java script code
by h_c_a_andersen (2 replies)
-
sharepoint calendar web part with events from sql table
by converter2009 (2 replies)
Related podcasts
-
StackOverflow uses ASP.NET MVC - Jeff Atwood and his technical team
Scott chats with Jeff Atwood of CodingHorror.com and most recently, StackOverflow.com. Jeff and Joel Spolsky and their technical team have created a new class of application using ASP.NET MVC. What works, what doesn't, and how did it all go down?
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
This thread is for discussions of ASP.NET and GDI+.