VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Wpf.UI Namespace / WpfImageViewer Class / Image Property
Example



In This Topic
    Image Property (WpfImageViewer)
    In This Topic
    Gets or sets the image currently being displayed in the WpfImageViewer.
    Syntax
    'Declaration
     
    <BrowsableAttribute(False)>
    Public Property Image As VintasoftImage
    [Browsable(false)]
    public VintasoftImage Image {get; set;}
    [Browsable(false)]
    public: __property VintasoftImage* get_Image();
    public: __property void set_Image( 
       VintasoftImage* value
    );
    [Browsable(false)]
    public:
    property VintasoftImage^ Image {
       VintasoftImage^ get();
       void set (    VintasoftImage^ value);
    }
    Remarks
    When you set the value of this property:
    Example
    This example shows how to show captured image from a webcam in WpfImageViewer.
    ''' <summary>
    ''' Image capture source.
    ''' </summary>
    Private _imageCaptureSource As Vintasoft.Imaging.Media.ImageCaptureSource
                
                
                
    ''' <summary> 
    ''' Initializes a new instance of the <see cref="MainWindow"/> class.
    ''' </summary>
    Public Sub New()
        InitializeComponent()
                
        ' get available image capture devices
        Dim availableDevices As System.Collections.ObjectModel.ReadOnlyCollection(Of Vintasoft.Imaging.Media.ImageCaptureDevice) = Vintasoft.Imaging.Media.ImageCaptureDeviceConfiguration.GetCaptureDevices()
                
        ' create new image capture source
        _imageCaptureSource = New Vintasoft.Imaging.Media.ImageCaptureSource()
        AddHandler _imageCaptureSource.CaptureCompleted, New System.EventHandler(Of Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs)(AddressOf ImageCaptureSource_CaptureCompleted)
                
        ' if there are available devices
        If availableDevices.Count <> 0 Then
            ' use the first image capture device
            _imageCaptureSource.CaptureDevice = availableDevices(0)
        End If
                
        AddHandler Loaded, New System.Windows.RoutedEventHandler(AddressOf MainWindow_Loaded)
        AddHandler Closed, New System.EventHandler(AddressOf MainWindow_Closed)
    End Sub
                
                
                
    ''' <summary>
    ''' Starts capturing from camera.
    ''' </summary>
    Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        ' if capture device is empty
        If _imageCaptureSource.CaptureDevice IsNot Nothing Then
            ' start the image capture source
            _imageCaptureSource.Start()
            ' initialize new image capture request
            _imageCaptureSource.CaptureAsync()
        End If
    End Sub
                
    ''' <summary>
    ''' Image is captured.
    ''' </summary>
    Private Sub ImageCaptureSource_CaptureCompleted(ByVal sender As Object, ByVal e As Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs)
        ' save reference to the previously captured image
        Dim oldImage As Vintasoft.Imaging.VintasoftImage = wpfImageViewer1.Image
                
        ' get captured image and show captured image in the image viewer           
        wpfImageViewer1.Image = e.GetCapturedImage()
                
        ' if previously captured image exists
        If oldImage IsNot Nothing Then
            ' dispose previously captured image
            oldImage.Dispose()
        End If
                
        ' if capture source is started
        If _imageCaptureSource.State = Vintasoft.Imaging.Media.ImageCaptureState.Started Then
            ' initialize new image capture request
            _imageCaptureSource.CaptureAsync()
        End If
    End Sub
                
    ''' <summary>
    ''' Form is closed.
    ''' </summary>
    Private Sub MainWindow_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
        ' stop the image capture source
        _imageCaptureSource.[Stop]()
    End Sub
    /// <summary>
    /// Image capture source.
    /// </summary>
    Vintasoft.Imaging.Media.ImageCaptureSource _imageCaptureSource;
                
                
                
    /// <summary> 
    /// Initializes a new instance of the <see cref="MainWindow"/> class.
    /// </summary>
    public MainWindow()
    {
        InitializeComponent();
                
        // get available image capture devices
        System.Collections.ObjectModel.ReadOnlyCollection<Vintasoft.Imaging.Media.ImageCaptureDevice> availableDevices =
            Vintasoft.Imaging.Media.ImageCaptureDeviceConfiguration.GetCaptureDevices();
                
        // create new image capture source
        _imageCaptureSource = new Vintasoft.Imaging.Media.ImageCaptureSource();
        _imageCaptureSource.CaptureCompleted +=
            new System.EventHandler<Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs>(ImageCaptureSource_CaptureCompleted);
                
        // if there are available devices
        if (availableDevices.Count != 0)
        {
            // use the first image capture device
            _imageCaptureSource.CaptureDevice = availableDevices[0];
        }
                
        Loaded += new System.Windows.RoutedEventHandler(MainWindow_Loaded);
        Closed += new System.EventHandler(MainWindow_Closed);
    }
                
                
                
    /// <summary>
    /// Starts capturing from camera.
    /// </summary>
    private void MainWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        // if capture device is empty
        if (_imageCaptureSource.CaptureDevice != null)
        {
            // start the image capture source
            _imageCaptureSource.Start();
            // initialize new image capture request
            _imageCaptureSource.CaptureAsync();
        }
    }
                
    /// <summary>
    /// Image is captured.
    /// </summary>
    private void ImageCaptureSource_CaptureCompleted(object sender, Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs e)
    {
        // save reference to the previously captured image
        Vintasoft.Imaging.VintasoftImage oldImage = wpfImageViewer1.Image;
                
        // get captured image and show captured image in the image viewer           
        wpfImageViewer1.Image = e.GetCapturedImage();
                
        // if previously captured image exists
        if (oldImage != null)
        {
            // dispose previously captured image
            oldImage.Dispose();
        }
                
        // if capture source is started
        if (_imageCaptureSource.State == Vintasoft.Imaging.Media.ImageCaptureState.Started)
        {
            // initialize new image capture request
            _imageCaptureSource.CaptureAsync();
        }
    }
                
    /// <summary>
    /// Form is closed.
    /// </summary>
    private void MainWindow_Closed(object sender, System.EventArgs e)
    {
        // stop the image capture source
        _imageCaptureSource.Stop();
    }
    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also