DICOM: View DICOM images in WinForms
In This Topic
The
DicomViewerTool class allows to:
- Apply VOI LUT to a RAW DICOM image and preview processed image in an image viewer.
- Zoom DICOM frame in image viewer.
- Slide DICOM frames in image viewer.
- Show DICOM metadata in image viewer.
Here is C#/VB.NET code that demonstrates how to view a DICOM image and display the DICOM image metadata in the image viewer:
/// <summary>
/// A visual tool that allows to show name and age of patient.
/// </summary>
public class CustomDicomViewerTool : Vintasoft.Imaging.Dicom.UI.VisualTools.DicomViewerTool
{
/// <summary>
/// Initializes a new instance of the <see cref="CustomDicomViewerTool"/> class.
/// </summary>
public CustomDicomViewerTool()
: this(true)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CustomDicomViewerTool" /> class.
/// </summary>
/// <param name="needUpdateViewerAfterApplyingVoiLut">
/// Determines that the image viewer must be updated after applying VOI lookup table to a DICOM image.
/// </param>
public CustomDicomViewerTool(bool needUpdateViewerAfterApplyingVoiLut)
: base(needUpdateViewerAfterApplyingVoiLut)
{
// clear the default text overlay
TextOverlay.Clear();
// create text overlay of VOI LUT
Vintasoft.Imaging.Dicom.UI.VisualTools.DicomImageVoiLutTextOverlay voiLutTextOverlay =
new Vintasoft.Imaging.Dicom.UI.VisualTools.DicomImageVoiLutTextOverlay();
// 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.Drawing.Brush textBrush = System.Drawing.Brushes.Blue;
// create text overlay
Vintasoft.Imaging.Dicom.UI.VisualTools.StandardDicomDataElementTextOverlay patientNameTextOverlay =
new Vintasoft.Imaging.Dicom.UI.VisualTools.StandardDicomDataElementTextOverlay(
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
Vintasoft.Imaging.Dicom.UI.VisualTools.StandardDicomDataElementTextOverlay patientAgeTextOverlay =
new Vintasoft.Imaging.Dicom.UI.VisualTools.StandardDicomDataElementTextOverlay(
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 he visual tool
TextOverlay.Add(patientAgeTextOverlay);
}
}
''' <summary>
''' A visual tool that allows to show name and age of patient.
''' </summary>
Public Class CustomDicomViewerTool
Inherits Vintasoft.Imaging.Dicom.UI.VisualTools.DicomViewerTool
''' <summary>
''' Initializes a new instance of the <see cref="CustomDicomViewerTool"/> class.
''' </summary>
Public Sub New()
Me.New(True)
End Sub
''' <summary>
''' Initializes a new instance of the <see cref="CustomDicomViewerTool" /> 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.UI.VisualTools.DicomImageVoiLutTextOverlay()
' 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.Drawing.Brush = System.Drawing.Brushes.Blue
' create text overlay
Dim patientNameTextOverlay As New Vintasoft.Imaging.Dicom.UI.VisualTools.StandardDicomDataElementTextOverlay(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
Dim patientAgeTextOverlay As New Vintasoft.Imaging.Dicom.UI.VisualTools.StandardDicomDataElementTextOverlay(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 he visual tool
TextOverlay.Add(patientAgeTextOverlay)
End Sub
End Class