This topic contains the following sections.
Your Visual Studio.NET application can display graphics and text over an acquired image.
See any of the following topics for details on acquiring an image:
- Acquiring Images with a CCD Camera and Frame Grabber
- Acquiring Images with a CDC Camera and Frame Grabber
- Acquiring Images with a Line Scan Camera
In addition, see the topic Displaying An Image for details on using a CogDisplay control to display the images you acquire in your .NET application.
VisionPro supports CogStaticGraphicsContainer graphics which cannot be moved or changed once they have been added to a CogDisplay image, and CogInteractiveGraphicsContainer graphics which can be moved or modified by the application or by the user if you enable the Interactive property.
The following C# statements add a static label to an existing application that displays images in the CogDisplay object CogDisplay1:
using Cognex.VisionPro;
private CogGraphicLabel cglCaption;
private Font myFont;
private void InitializeStaticGraphics()
{
cglCaption = new CogGraphicLabel();
// Set it's text and alignment properties
cglCaption.Text = "Cognex Display Control";
cglCaption.Alignment = CogGraphicLabelAlignmentConstants.TopLeft;
// .NET fonts are read only, so create a new font and then
// push this font object onto the Font property of the label
// myFont = new Font("Comic Sans MS", 18, FontStyle.Bold);
myFont = new Font("Comic Sans MS", 16, FontStyle.Bold);
cglCaption.Font = myFont;
// Set its space to be '#' - anchored to the image
cglCaption.SelectedSpaceName = "#";
// Position the label over the CogDisplay
cglCaption.X = 0;
cglCaption.Y = 0;
// Add the label to the CogDisplay
cogDisplay1.StaticGraphics.Add(cglCaption, cglCaption.Text);
}The following C# statements add an interactive label to an existing application that displays images in the CogDisplay object CogDisplay1. The application contains a TextBox control, textBox1, and a button button2. Each time a user enters text in the TextBox control and presses the button, the interactive label in CogDisplay1 updates with the text the user entered.
using Cognex.VisionPro;
private CogGraphicLabel cglCaption;
private Font myFont;
private void InitializeInteractiveGraphics()
{
cglCaption = new CogGraphicLabel();
// Set it's text and alignment properties
cglCaption.Text = "Cognex Display Control";
cglCaption.Alignment = CogGraphicLabelAlignmentConstants.TopLeft;
// .NET fonts are read only, so create a new font and then
// push this font object onto the Font property of the label
// myFont = new Font("Comic Sans MS", 18, FontStyle.Bold);
myFont = new Font("Comic Sans MS", 16, FontStyle.Bold);
cglCaption.Font = myFont;
// Set its space to be '*' - anchored to the image
cglCaption.SelectedSpaceName = "*";
// Position the label over the CogDisplay
cglCaption.X = 0;
cglCaption.Y = 0;
// Add the label to the CogDisplay
cogDisplay1.InteractiveGraphics.Add(cglCaption, cglCaption.Text, false);
}
private void button2_Click(object sender, System.EventArgs e)
{
string output;
output = "Text: " + textBox1.Text;
cglCaption.Text = output;
}