jhylands

Writing text on an image

May 1st, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.91 KB | None | 0 0
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         ' Load up a graphic
  3.         Dim cityimg As Bitmap = New Bitmap("c:\\ourcityimage.jpg")
  4.         ' Create a graphics object to work on the image
  5.         Dim imgGraphics As Graphics = Graphics.FromImage(cityimg)
  6.         ' Create a white rectangle on our image that is x=8, y=8 30 in width and 15 in height
  7.         imgGraphics.FillRectangle(Brushes.White, 8, 8, 30, 15)
  8.         ' Create a 10 pt font in verdana and write test in black, putting its coordinates in our white rectangle
  9.         Dim ourFont As New Font("Verdana", 10)
  10.         imgGraphics.DrawString("test", ourFont, New SolidBrush(Color.Black), 10, 9)
  11.         ' Get a handle for the form and draw right on the form
  12.         Dim formGraphics As Graphics = Graphics.FromHwnd(Me.Handle)
  13.         formGraphics.DrawImage(cityimg, 10, 10)
  14. End Sub
Advertisement
Add Comment
Please, Sign In to add comment