VintaSoft Imaging .NET SDK v8.7
In This Topic
    DICOM: View DICOM images in WPF
    In This Topic

    The WpfDicomViewerTool class allows to:


    Here is an example that demonstrates how to view a DICOM image and display the DICOM image metadata in the image viewer:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Dicom
    ' - Vintasoft.Imaging.Dicom.Wpf.UI
    
    ''' <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.UI.AnchorType.Left Or Vintasoft.Imaging.UI.AnchorType.Bottom
            ' add text overlay to visual tool
            TextOverlay.Add(voiLutTextOverlay)
    
    
            ' the text anchor
            Dim textAnchor As Vintasoft.Imaging.UI.AnchorType = Vintasoft.Imaging.UI.AnchorType.Bottom Or Vintasoft.Imaging.UI.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
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Dicom
    // - Vintasoft.Imaging.Dicom.Wpf.UI
    
    /// <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.UI.AnchorType.Left | Vintasoft.Imaging.UI.AnchorType.Bottom;
            // add text overlay to visual tool
            TextOverlay.Add(voiLutTextOverlay);
    
    
            // the text anchor
            Vintasoft.Imaging.UI.AnchorType textAnchor =
                Vintasoft.Imaging.UI.AnchorType.Bottom | Vintasoft.Imaging.UI.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);
        }
    }