VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
In This Topic
    DICOM: View DICOM images in WPF
    In This Topic
    VintaSoft DICOM .NET Plug-in contains WPF UI-control WpfDicomSeriesManagerControl that allows to display information about DICOM series grouped by patient and study, navigate by DICOM series, asynchronously add DICOM files.

    Also VintaSoft DICOM .NET Plug-in contains 2 visual tools for DICOM images in WPF image viewer: WpfDicomViewerTool, WpfEcgVisualTool.


    WpfDicomSeriesManagerControl UI-control

    The WpfDicomSeriesManagerControl allows to:
    Here is screenshot of WpfDicomSeriesManagerControl UI-control in VintaSoft WPF DICOM Viewer Demo:


    WpfDicomViewerTool class

    The WpfDicomViewerTool class allows to to zoom and slide DICOM frames in WPF image viewer. Also tool allows to apply VOI LUT to a DICOM frame in WPF image viewer. Also tool allows to display metadata of DICOM frame in WPF image viewer.

    Here is C#/VB.NET code that demonstrates how to view a DICOM image and display the DICOM image metadata in WPF image viewer:
    /// <summary>
    /// A visual tool that allows to show name and age of patient.
    /// </summary>
    public class CustomWpfDicomViewerTool : Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfDicomViewerTool
    {
    
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomWpfDicomViewerTool"/> class.
        /// </summary>
        public CustomWpfDicomViewerTool()
            : this(true)
        {
        }
    
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomWpfDicomViewerTool" /> class.
        /// </summary>
        /// <param name="needUpdateViewerAfterApplyingVoiLut">
        /// Determines that the image viewer must be updated after applying VOI lookup table to a DICOM image.
        /// </param>
        public CustomWpfDicomViewerTool(bool needUpdateViewerAfterApplyingVoiLut)
            : base(needUpdateViewerAfterApplyingVoiLut)
        {
            // clear the default text overlay
            TextOverlay.Clear();
    
    
            // create text overlay of VOI LUT
            Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfDicomImageVoiLutTextOverlay voiLutTextOverlay =
                new Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfDicomImageVoiLutTextOverlay();
            // set the anchor of text
            voiLutTextOverlay.Anchor = Vintasoft.Imaging.AnchorType.Left | Vintasoft.Imaging.AnchorType.Bottom;
            // add text overlay to visual tool
            TextOverlay.Add(voiLutTextOverlay);
    
    
            // the text anchor
            Vintasoft.Imaging.AnchorType textAnchor =
                Vintasoft.Imaging.AnchorType.Bottom | Vintasoft.Imaging.AnchorType.Right;
            // the text color
            System.Windows.Media.Brush textBrush = System.Windows.Media.Brushes.Blue;
    
    
            // create text overlay of patient name
            Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfStandardDicomDataElementTextOverlay patientNameTextOverlay =
                new Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfStandardDicomDataElementTextOverlay(
                    Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientName);
            // set the anchor of text
            patientNameTextOverlay.Anchor = textAnchor;
            // set the color of text
            patientNameTextOverlay.TextBrush = textBrush;
            // set text format of text
            patientNameTextOverlay.TextFormat = "Name: {0}";
            // add text overlay to visual tool
            TextOverlay.Add(patientNameTextOverlay);
    
    
            // create text overlay of patient age
            Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfStandardDicomDataElementTextOverlay patientAgeTextOverlay =
                new Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfStandardDicomDataElementTextOverlay(
                     Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientAge);
            // set the anchor of text
            patientAgeTextOverlay.Anchor = textAnchor;
            // set the color of text
            patientAgeTextOverlay.TextBrush = textBrush;
            // set text format of text
            patientAgeTextOverlay.TextFormat = "Age: {0}";
            // add text overlay to the visual tool
            TextOverlay.Add(patientAgeTextOverlay);
        }
    }
    
    ''' <summary>
    ''' A visual tool that allows to show name and age of patient.
    ''' </summary>
    Public Class CustomWpfDicomViewerTool
        Inherits Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfDicomViewerTool
    
        ''' <summary>
        ''' Initializes a new instance of the <see cref="CustomWpfDicomViewerTool"/> class.
        ''' </summary>
        Public Sub New()
            Me.New(True)
        End Sub
    
        ''' <summary>
        ''' Initializes a new instance of the <see cref="CustomWpfDicomViewerTool" /> class.
        ''' </summary>
        ''' <param name="needUpdateViewerAfterApplyingVoiLut">
        ''' Determines that the image viewer must be updated after applying VOI lookup table to a DICOM image.
        ''' </param>
        Public Sub New(needUpdateViewerAfterApplyingVoiLut As Boolean)
            MyBase.New(needUpdateViewerAfterApplyingVoiLut)
            ' clear the default text overlay
            TextOverlay.Clear()
    
    
            ' create text overlay of VOI LUT
            Dim voiLutTextOverlay As New Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfDicomImageVoiLutTextOverlay()
            ' set the anchor of text
            voiLutTextOverlay.Anchor = Vintasoft.Imaging.AnchorType.Left Or Vintasoft.Imaging.AnchorType.Bottom
            ' add text overlay to visual tool
            TextOverlay.Add(voiLutTextOverlay)
    
    
            ' the text anchor
            Dim textAnchor As Vintasoft.Imaging.AnchorType = Vintasoft.Imaging.AnchorType.Bottom Or Vintasoft.Imaging.AnchorType.Right
            ' the text color
            Dim textBrush As System.Windows.Media.Brush = System.Windows.Media.Brushes.Blue
    
    
            ' create text overlay of patient name
            Dim patientNameTextOverlay As New Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfStandardDicomDataElementTextOverlay(Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientName)
            ' set the anchor of text
            patientNameTextOverlay.Anchor = textAnchor
            ' set the color of text
            patientNameTextOverlay.TextBrush = textBrush
            ' set text format of text
            patientNameTextOverlay.TextFormat = "Name: {0}"
            ' add text overlay to visual tool
            TextOverlay.Add(patientNameTextOverlay)
    
    
            ' create text overlay of patient age
            Dim patientAgeTextOverlay As New Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools.WpfStandardDicomDataElementTextOverlay(Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientAge)
            ' set the anchor of text
            patientAgeTextOverlay.Anchor = textAnchor
            ' set the color of text
            patientAgeTextOverlay.TextBrush = textBrush
            ' set text format of text
            patientAgeTextOverlay.TextFormat = "Age: {0}"
            ' add text overlay to the visual tool
            TextOverlay.Add(patientAgeTextOverlay)
        End Sub
    End Class
    


    WpfEcgVisualTool class

    The WpfEcgVisualTool class allows to measure electrocardiogram in WPF image viewer.

    Here is C#/VB.NET code that demonstrates how to display information about selection in ECG visual tool:
    /// <summary>
    /// Helps to display information about selection in <see cref="Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool"/>.
    /// </summary>
    public class EcgVisualToolHelper : System.IDisposable
    {
    
        #region Fields
    
        /// <summary>
        /// The image viewer.
        /// </summary>
        Vintasoft.Imaging.UI.ImageViewer _viewer;
    
        /// <summary>
        /// The label.
        /// </summary>
        System.Windows.Forms.Label _label;
    
        #endregion
    
    
    
        #region Constructors
    
        /// <summary>
        /// Initializes a new instance of the <see cref="EcgVisualToolHelper"/> class.
        /// </summary>
        /// <param name="viewer">The image viewer.</param>
        /// <param name="label">The label.</param>
        public EcgVisualToolHelper(Vintasoft.Imaging.UI.ImageViewer viewer, System.Windows.Forms.Label label)
        {
            _viewer = viewer;
            _label = label;
    
            // create visual tool
            Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool visualTool = new Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool();
            visualTool.SelectionChanged += EcgVisualTool_SelectionChanged;
    
            // set the visual tool
            _viewer.VisualTool = visualTool;
        }
    
        #endregion
    
    
    
        #region Methods
    
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (_viewer.VisualTool is Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool)
                _viewer.VisualTool = null;
        }
    
        /// <summary>
        /// Handles the SelectionChanged event of the EcgVisualTool control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Vintasoft.Imaging.PropertyChangedEventArgs{Vintasoft.Primitives.VintasoftRect}"/> instance containing the event data.</param>
        private void EcgVisualTool_SelectionChanged(object sender, Vintasoft.Imaging.PropertyChangedEventArgs<Vintasoft.Primitives.VintasoftRect> e)
        {
            // if value is specified
            if (e.NewValue.Width != 0 || e.NewValue.Height != 0)
            {
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
    
                // add time information
                stringBuilder.AppendFormat("{0:F0} ms", e.NewValue.Width * 1000);
    
                if (e.NewValue.Height != 0)
                    // add voltage information
                    stringBuilder.AppendFormat(", {0:F0} μV", e.NewValue.Height * 1000);
    
                // update text
                _label.Text = stringBuilder.ToString();
            }
            else
            {
                // remove text
                _label.Text = string.Empty;
            }
        }
    
        #endregion
    
    }
    
    ''' <summary>
    ''' Helps to display information about selection in <see cref="Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool"/>.
    ''' </summary>
    Public Class EcgVisualToolHelper
        Implements System.IDisposable
    
        #Region "Fields"
    
        ''' <summary>
        ''' The image viewer.
        ''' </summary>
        Private _viewer As Vintasoft.Imaging.UI.ImageViewer
    
        ''' <summary>
        ''' The label.
        ''' </summary>
        Private _label As System.Windows.Forms.Label
    
        #End Region
    
    
    
        #Region "Constructors"
    
        ''' <summary>
        ''' Initializes a new instance of the <see cref="EcgVisualToolHelper"/> class.
        ''' </summary>
        ''' <param name="viewer">The image viewer.</param>
        ''' <param name="label">The label.</param>
        Public Sub New(viewer As Vintasoft.Imaging.UI.ImageViewer, label As System.Windows.Forms.Label)
            _viewer = viewer
            _label = label
    
            ' create visual tool
            Dim visualTool As New Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool()
            AddHandler visualTool.SelectionChanged, AddressOf EcgVisualTool_SelectionChanged
    
            ' set the visual tool
            _viewer.VisualTool = visualTool
        End Sub
    
        #End Region
    
    
    
        #Region "Methods"
    
        ''' <summary>
        ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        ''' </summary>
        Public Sub Dispose() Implements System.IDisposable.Dispose
            If TypeOf _viewer.VisualTool Is Vintasoft.Imaging.Dicom.UI.VisualTools.EcgVisualTool Then
                _viewer.VisualTool = Nothing
            End If
        End Sub
    
        ''' <summary>
        ''' Handles the SelectionChanged event of the EcgVisualTool control.
        ''' </summary>
        ''' <param name="sender">The source of the event.</param>
        ''' <param name="e">The <see cref="Vintasoft.Imaging.PropertyChangedEventArgs{Vintasoft.Primitives.VintasoftRect}"/> instance containing the event data.</param>
        Private Sub EcgVisualTool_SelectionChanged(sender As Object, e As Vintasoft.Imaging.PropertyChangedEventArgs(Of Vintasoft.Primitives.VintasoftRect))
            ' if value is specified
            If e.NewValue.Width <> 0 OrElse e.NewValue.Height <> 0 Then
                Dim stringBuilder As New System.Text.StringBuilder()
    
                ' add time information
                stringBuilder.AppendFormat("{0:F0} ms", e.NewValue.Width * 1000)
    
                If e.NewValue.Height <> 0 Then
                    ' add voltage information
                    stringBuilder.AppendFormat(", {0:F0} ?V", e.NewValue.Height * 1000)
                End If
    
                ' update text
                _label.Text = stringBuilder.ToString()
            Else
                ' remove text
                _label.Text = String.Empty
            End If
        End Sub
    
        #End Region
    
    End Class