Saving an Image (JPEG) to File Short code snippet that illustrates how to freeze an image data stream and save the frozen image as a JPEG to file.
Language: | .NET C#/Visual Basic
Version: | 3.3
Author: | IC Imaging Control Support Department
Requirements: |
Software: | IC Imaging Control 3.3, Visual Studio™ 2010
Hardware: | Camera, converter or grabber with WDM Stream Class drivers.
Download C# sample | Save JPEG - C#

The window of the resulting application looks as follows:

First of all, IC Imaging Control and a button to save the image as a JPEG are dragged onto the form.

The program starts by opening the built-in dialog that allows the end-user to select a video capture device (.ShowDeviceSettingsDialog). At the end of the function Form1_Load(), the live image data stream from the video capture device is displayed, using .LiveStart.

    C#

    private void Form1_Load(object sender, System.EventArgs e)
    {
        icImagingControl1.ShowDeviceSettingsDialog();

        if( icImagingControl1.DeviceValid )
        {
            icImagingControl1.LiveStart();
        }
        else
        {
            Close();
        }
    }

When the user clicks "Save Jpeg", .MemorySnapImage grabs an image from the image data stream and writes it into an internal ring buffer.

.ImageActiveBuffer provides an ImageBuffer object that contains the grabbed image. .SaveAsJpeg writes it into a JPEG file, using the file name and the desired quality (0 to 100) as parameters:

    C#

    private void button1_Click(object sender, System.EventArgs e)
    {
        icImagingControl1.MemorySnapImage();

        SaveFileDialog dlg = new SaveFileDialog();
        dlg.AddExtension = true;
        dlg.DefaultExt = "jpg";
        dlg.Filter = "JPEG Images (*.jpg)|*.jpg||";
        dlg.OverwritePrompt = true;

        if( dlg.ShowDialog() == DialogResult.OK )
        {
            icImagingControl1.ImageActiveBuffer.SaveAsJpeg( dlg.FileName, 100 );
        }
    }