2 Replies - 7086 Views - Last Post: 31 October 2007 - 12:28 PM Rate Topic: -----

#1 Chubber  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 131
  • Joined: 16-October 06

Best graphical toolkit for VB image manipulation?

Posted 31 October 2007 - 10:35 AM

I need to add a unique number to every image I am given. I have to modify thousands of images. Most are approximately the same size (page scans) but may be as small as a few inches to as big as 20 inches square. I need to add a 10 digit number in black on a white background to every image. The numbers will be about 50 pixels high. The input formats will probably be JPG though a few might be GIF.

Can I do this in the native graphical classes in VB.NET? Or should I look at toolkits like LEAD? It has been about 10 years since I did this kind of graphics manipulation in VB, so I don't know the toolkits and graphics classes and I don't want to go inventing the wheel.

Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: Best graphical toolkit for VB image manipulation?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,845
  • Joined: 18-April 07

Re: Best graphical toolkit for VB image manipulation?

Posted 31 October 2007 - 11:37 AM

Well VB.NET can do this quite well using the GDI library already in the language. All you need to do is load up the image, put on a white rectangle, draw your black text on top and there you go. All that would be left is to save it, I will let you handle that part.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		' Load up a graphic
		Dim cityimg As Bitmap = New Bitmap("c:\\ourcityimage.jpg")

		' Create a graphics object to work on the image
		Dim imgGraphics As Graphics = Graphics.FromImage(cityimg)

		' Create a white rectangle on our image that is x=8, y=8 30 in width and 15 in height
		imgGraphics.FillRectangle(Brushes.White, 8, 8, 30, 15)

		' Create a 10 pt font in verdana and write test in black, putting its coordinates in our white rectangle
		Dim ourFont As New Font("Verdana", 10)
		imgGraphics.DrawString("test", ourFont, New SolidBrush(Color.Black), 10, 9)

		' Get a handle for the form and draw right on the form
		Dim formGraphics As Graphics = Graphics.FromHwnd(Me.Handle)
		formGraphics.DrawImage(cityimg, 10, 10)

End Sub



Just follow along with the in code comments to see how it is done. This will result in the image below...

Posted Image

As you can see we put this in the upper left corner of the image. You can adjust it to be wherever you like. To fit the dynamic graphic size in a lower right corner, for instance, you would be using a dynamic setting for your FillRectangle and drawstring methods. Something along the lines of imageWidth - 10, imageHeight - 10.

I am sure you get the idea.

Enjoy!

"At DIC we be GDI coding ninjas!" :snap:
Was This Post Helpful? 0
  • +
  • -

#3 Chubber  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 131
  • Joined: 16-October 06

Re: Best graphical toolkit for VB image manipulation?

Posted 31 October 2007 - 12:28 PM

Wow. Is it really that easy? I guess the core bitmap routines have come a long way since I last played with it. I wonder what image types the Bitmap object can take as a constructor? Tiff? Thanks for the tip, I think that I can take it from here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1