IC Imaging Control .NET

Grabbing an Image

Grabbing an Image

This chapter shows you how to grab a still image from the video stream and save it to a .png file.

The source code for the VB.NET and C# versions of this sample program can be found in the directories samples\VB *\Grabbing an Image and samples\C# *\Grabbing an Image in your My Documents/IC Imaging Control 3.4 directory.

Setting up the Project

Create a new project and add IC Imaging Control to the form. Before you run the program, select the video device, input and video format as shown in the FirstSteps chapter. Alternatively, run the program without selecting a device. In this case, the program shows the device selection dialog provided by IC Imaging Control. If you close this dialog without having made a selection, the program will display an error message and terminate.

Now, add 3 buttons to the form and label them "Start Live", "Stop Live" and "Save Bitmap". Name the buttons cmdStartLive, cmdStopLive and cmdSaveBitmap respectively.

Add calls to IC Imaging Control's LiveStart and LiveStop methods:

Private Sub cmdStartLive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStartLive.Click IcImagingControl1.LiveStart() End Sub
private void cmdStartLive_Click(object sender, EventArgs e) { icImagingControl1.LiveStart(); }
Private Sub cmdStopLive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopLive.Click IcImagingControl1.LiveStop() End Sub
private void cmdStopLive_Click(object sender, EventArgs e) { if (icImagingControl1.LiveVideoRunning == true) icImagingControl1.LiveStop(); }

Run the program. You can now start and stop the live image by clicking on the respective buttons.


The video format describes the width, height and color depth of the video stream. Select the one you would like to use.


When the live video is running, a call to the MemorySnapImage method will grab the image that is currently being displayed and store it in IC Imaging Control's image buffer. When you stop the live image, however, the last frame of the live image is stored automatically. In both cases, the grabbed image can be saved with the MemorySaveImage method. Only a common dialog box has to be added, so that a filename can be selected.

Private Sub cmdSaveBitmap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveBitmap.Click IcImagingControl1.MemorySnapImage() ' Call the save file dialog to enter the file name of the image Dim saveFileDialog1 As New SaveFileDialog saveFileDialog1.Filter = "bmp files (*.png)|*.png|All files (*.*)|*.*" saveFileDialog1.FilterIndex = 1 saveFileDialog1.RestoreDirectory = True If saveFileDialog1.ShowDialog() = DialogResult.OK Then ' Save the image. IcImagingControl1.MemorySaveImage(saveFileDialog1.FileName) End If End Sub
private void cmdSaveBitmap_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1; icImagingControl1.MemorySnapImage(); saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "bmp files (*.png)|*.png|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { icImagingControl1.MemorySaveImage(saveFileDialog1.FileName); } }

Now you can start the live image to adjust your cameras brightness and focus, and then stop the live display and save the captured image.

<< Programmer's Guide

Get in touch with us

About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us