You are here: Start » AVL.NET » Adaptive Vision Library .NET Usage » Settings

Settings

The following example is a simple Settings class usage example.

The application is a single-form application that calls the GradientImage function for a test image. The function has one diagnostic output which provides directions image only if AvlNet.Settings.IsDiagnosticModeEnabled is set to true. User may modify this value with checked state of the Diagnostic mode tool strip button.

The main window is composed of three PictureBox objects, one ToolStripButton and a ToolStripComboBox that enables choosing a test image:

using System;
using System.Windows.Forms;

namespace Settings
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            foreach (var imageType in Enum.GetNames(typeof(AvlNet.TestImageId)))
                testImageTypeCombo.Items.Add(imageType);

            testImageTypeCombo.SelectedIndex = 0;

            UpdateImages();
        }

        private void diagnosticModeButton_CheckedChanged(object sender, EventArgs e)
        {
            AvlNet.Settings.IsDiagnosticModeEnabled = (sender as ToolStripButton).Checked;

            UpdateImages();
        }

        private void ResetPictureBox(PictureBox pictureBox)
        {
            if (pictureBox.Image != null)
            {
                pictureBox.Image.Dispose();
                pictureBox.Image = null;
            }
        }

        private void UpdateImages()
        {
            // Reset picture boxes
            ResetPictureBox(gradientImagePictureBox);
            ResetPictureBox(originalImagePictureBox);
            ResetPictureBox(directionsImagePictureBox);

            using (AvlNet.Image
                rgbImage = new AvlNet.Image(),
                gradientImage = new AvlNet.Image(),
                directionsImage = new AvlNet.Image())
            {

                AvlNet.TestImageId testImageId = (AvlNet.TestImageId)Enum.Parse(typeof(AvlNet.TestImageId), testImageTypeCombo.SelectedItem.ToString());

                // Call AvlNet functions
                AvlNet.AVL.TestImage(testImageId, rgbImage, null);
                AvlNet.AVL.GradientImage(rgbImage, null, AvlNet.GradientOperator.Gauss, 2.0f, null, gradientImage, directionsImage);

                // Set picture box images
                originalImagePictureBox.Image = rgbImage.CreateBitmap();
                gradientImagePictureBox.Image = gradientImage.CreateBitmap();

                if (directionsImage.Valid)
                    directionsImagePictureBox.Image = directionsImage.CreateBitmap();
            }
        }

        private void testImageTypeCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateImages();
        }
    }
}
Previous: AVL.NET Designers example Next: Function Reference