WorldofASP.NET : ASP.NET Directory, Tutorial, Hosting, and Source Code
You are 1 of 106 users


WorldofASP.NET >> VB.NET Programming >> Unedited VB.NET

Create Dynamic Image with Text

Create the image with text on fly.
Published Date : 07 Jul 2008
Author : Sandeep Dubey
Language : VB.NET
Platform : .NET,.NET Compact Framework
Technology : Visual Studio,ASP.NET,Win Forms,Web Forms
Views : 561
Rating : (1 votes so far)



Introduction

There are many situation when require to create dynamic image with text.  It is possible to create dynamic image with text and we can create the image with particular height and width.

Main

For doing this we require to import three Namespaces (System.Drawing, System.Drawing.Text, System.Drawing.Imaging) .

 

Below find the complete function  that creates the image on the fly:

 

Public Shared Function WriteImage(ByVal Text As String, ByVal BackgroundColor As Color, ByVal iWidth As Int16, ByVal iHeight As Int16) As Bitmap

1)     Dim oBitmap As Bitmap = New Bitmap(iWidth, iHeight)

2)    Dim oGraphic As Graphics = Graphics.FromImage(oBitmap)

3)    Dim oColor As System.Drawing.Color

4)    Dim sText As String = Text

5)   Dim sFont As String = "Black"

6)   oColor = BackgroundColor

7)   Dim oBrush As New SolidBrush(oColor)

8)   Dim oBrushWrite As New SolidBrush(Color.Black)

9)   oGraphic.FillRectangle(oBrush, 0, 0, iWidth, iHeight)

10)  oGraphic.TextRenderingHint = TextRenderingHint.AntiAlias

11   Dim oFont As New Font(sFont, 8)

12)  Dim oPoint As New Point(5, 5)

13)  oGraphic.DrawString(sText, oFont, oBrushWrite, oPoint)

14)    Return oBitmap

End Function

Explanation:
WriteImage function take 4 parameters
1) Text : Text to be written on image.
2) BackgroundColor: Background color of the image.
3) iWidth: Width of the image.
4) iHeight: Height of the image. 

 

Line 1: First we have created the object of Bitmap of require size.

Line 2:Then create the graphics for bitmap image.

Line 3: Create the object of Color.
 
Line 4: Create the object of String type and assign the Text Parameter value.

Line 5: Create the object of String type and assign the Font value for Text.

Line 6: Assign the color for brush.

Line 7: Create the object for brush using color parameter.

Line 8: Create the object of SolidBrush.

Line9: Create the rectangle using grapich.

Line 10: Define TextRenderingHint for graphics.

Line11 and Line 12: Crate the object of Font and Point.

Line 13 : Write the text on image using graphics object.

Download Source Code





Other Related and Popular Articles :


Author Profile : Sandeep Dubey

Click here to view Author Profile


How would you rate the quality of this content?
Poor Excellent

Comments

Leave New Comments


Article Content copyright by Sandeep Dubey
Everything else Copyright © by WorldofASP.NET 2009

Category
.NET 3.5
AJAX and ATLAS
ASP.NET
C# Programming
Classic ASP
Enterprise Systems
General .NET
VB.NET Programming
Announcements
Earn Cash by writing an article or review
For more info Click here







Legend : - Within 3 Days - Within 6 Days - Within 9 Days

Home | Add Resources | Sponsored Listings | Advertise with Us | SiteMap 1 | SiteMap 2 | Link To Us | Contact Us
© 2002-2009 Worldofasp.net ASP.NET Directory, Hosting and Tutorials | All rights reserved
Our Partners : ASP.NET Web Hosting | Windows Web Hosting | ASP.NET Hosting | Phone Card | PHP Directory | Bangkok Hotels |Calling Card |Stock Investing