Victor Image Processing Library How-to Tips

Annotation -- Adding Text to an Image

Annotation is the placing of text into an image. The uses can include entering data into a form before printing, labeling features of an image, and adding captions to pictures.

     
The image of a form   The annotated image


Victor Library for 32-bit Windows holds an image in memory and by calling the addtext function you can easily specify a text string, color, position, and size to add. More more control over the text, use the addtextex function.

To save the image, call one of the Victor savefile functions in the Victor Library.


VB.NET Source Code | VB Source Code | C Source Code


Annotate, Add Text to an Image - the VB.NET Source Code

This function is implemented in the example desktop program vicnet1.net.

In this function we add text to the current image being processed as defined by the vicnet1 application's global image descriptor, vimage. Requires Victor Image Processing Library for 32-bit Windows v 6.0 or higher.

Private Sub Addtext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addtext.Click
        ' text | add text
	Dim rcode As Integer
	Dim text As String
	Dim textheight As Integer
	Dim color As Integer
        ' Add text to the global vimage
	text = "Your name here"
	textheight = 20	 ' 20 pt
	color = 0		 ' Black
	vimage.stx = 10  ' Position for text (10, 20)
	vimage.sty = 20
        ' Write the text into the image area for the annotation
	rcode = addtext(color, textheight, "Courier New", text, vimage)
	vimage.stx = 0   ' Restore position to (0,0) for future operations 
	vimage.sty = 0
	VicimagetoPicturebox(vimage, PictureBox1)
	PictureBox1.Refresh()
End Sub


Annotate, Add Text to an Image - the Visual Basic Source Code

In this function we use the image area defined by the image descriptor as the rectangular area in which to place the text. Requires Victor Image Processing Library for 32-bit Windows v 6.0 or higher.
Public Function annotateimage() As Long
   Dim rcode As Long
   Dim resimg As imgdes
   Dim text As String
   Dim textheight As Integer
   Dim color As Integer
   Dim filedata As TiffData
   Dim filename As String
   filename = "test.tif"  
   rcode = tiffinfo(filename, filedata)
   If (rcode = NO_ERROR)  Then  
	rcode =  allocimage(resimg, filedata.width, filedata.length,  filedata.vbitcount) 
	If (rcode = NO_ERROR)
		Then rcode = loadtif(filename,  resimg) 
		If (rcode <>  NO_ERROR) Then
			GoTo bottom
		End If
	End If
    End If
    
        ' Successfully loaded the tiff image, ready to add text to it 
    text = "Your name here"
   resimg.stx = 10  ' Position for text (10, 20)
   resimg.sty = 20
   
   
        ' Write the text into the image area for the annotation
   rcode = addtext(color, textheight, "Courier New", text, vimage)
   
   
   resimg.stx = 0   ' Restore position to (0,0) for future operations 
   resimg.sty = 0
   rcode = savetif("testover.tif", resimg, 0)
   freeimage resimg
bottom:
   annotateimage = rcode
End Function


Annotate, Add Text to an Image - the C Source Code

In this function we use the image area defined by the image descriptor as the rectangular area in which to place the text. Requires Victor Image Processing Library for 32-bit Windows v 6.0 or higher.
int annotate(imgdes *resimg, char far *text)
{
	int rcode = NO_ERROR;
	int textheight;
	int color;
        // Add text to the global vimage
		textheight = 20;	 ' 20 pt
		color = 0;		 ' Black
		resimg->stx = 10;  ' Position for text (10, 20)
		resimg->sty = 20;
        ' Write the text into the image area for the annotation
		rcode = addtext(color, textheight, "Courier New", text, vimage);
		resimg->stx = 0;   ' Restore position to (0,0) for future operations 
		resimg->sty = 0;
	return(rcode);
}

Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code




Copyright 1997 - 2006 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.