Electronic documents are used in nearly every business environment. The electronic image is often routed directly from one person to another based on a set of workflow rules. Before sending the document to the next user, the current user might have placed a post-it note on the paper document with a handwritten note. Text can be placed on electronic images in VB.Net using the GDI+ Graphics class. GDI+ contains classes for drawing, imaging and printing.
- Skill level:
- Moderately Challenging
Other People Are Reading
Import the GDI+ classes "System.Drawing.Imaging" and "System.Drawing" at the beginning of your VB.Net program. Define a function or subroutine that will perform the action of adding text to the image. Name it something meaningful, such as "AddText."
Define variables inside the "AddText" function to reference the image object, the brush object and the size of the image. The size variable needs to reference "System.Drawing.Size." Set the image equal to a picture file using "System.Drawing.Image.FromFile(FileName)," where "FileName" is the path to the image to be displayed in the program.
Create a new image that is essentially a copy of the original image. "System.Drawing.Bitmap" requires the image and the size as parameters to create a new bitmap image.
Create a new graphics object from the newly created bitmap image, passing the bitmap image variable to "System.Drawing.Graphics.FromImage(NewBitMap)." With the graphics object, many different objects can be drawn on the image.
Use the "DrawString" method to add text to the image. Pass the text string, font, brush and position to the "DrawString" method. Referencing the new bitmap object created earlier, call the "Save" method passing the new image object and the format. Release the new bitmap object by calling the "Dispose" method.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for