An Image File object allows you to acquire images from an image file, as well as save acquired image to an image file for later use. VisionPro offers several classes for an Image File object, depending on the image format you want to use:
- Use a CogImageFileCDB object for CDB/IDB files
- Use a CogImageFileBMP object for bitmap files
- Use a CogImageFileTIFF object for TIFF files
If your application requires you to read multiple file types, use the generic CogImageFile object.
Reading an image file with an Image File object requires the following steps:
- Create an Image File object.
- Open the image file for reading.
- Acquire images for use and display.
The following C# statements are taken from a .NET Windows application with a Windows form containing a CogDisplay control and one button:
using Cognex.VisionPro;
using Cognex.VisionPro.ImageFile;
private CogImageFileCDB myImageFileOperator;
private int counter;
private int maxImages;
private void InitializeFifo()
{
myImageFileOperator = new CogImageFileCDB();
myImageFileOperator.Open("C:\\Program Files\\Cognex\\VisionPro\\Images\\barcode.cdb", CogImageFileModeConstants.Read);
counter = 0;
maxImages = myImageFileOperator.Count;
}
private void button1_Click(object sender, System.EventArgs e)
{
cogDisplay1.Image = myImageFileOperator[counter];
counter = counter + 1;
if (counter == maxImages)
counter = 0;
}Saving Images to an Image Database File
See the topic Save Images to an Image Database File for details on saving images to file.