LoadJson(DicomDataSet,Stream,DicomDataSetLoadJsonFlags,LoadJsonBeforeElementCallback,LoadJsonAfterElementCallback) Method

Summary

Loads a stream containing a DICOM-encoded JSON file.

Syntax
C#
VB
C++
<ExtensionAttribute()> 
Public Overloads Shared Sub LoadJson( _ 
   ByVal ds As DicomDataSet, _ 
   ByVal stream As Stream, _ 
   ByVal jsonFlags As DicomDataSetLoadJsonFlags, _ 
   ByVal cbBefore As LoadJsonBeforeElementCallback, _ 
   ByVal cbAfter As LoadJsonAfterElementCallback _ 
)  

Parameters

ds
The Data Set that will be created and populated with the contents of the DICOM JSON input file.

stream
The name of the input JSON file.

jsonFlags
Flags that affect whether to ignore binary or all data from the DICOM JSON input file.

cbBefore
Optional callback that allows you to modify how the input JSON file elements and values are used.

cbAfter
Optional callback that allows you to change the DicomElement after it has been added to the DicomDataSet.

Remarks

Use this method to read the contents of a DICOM JSON file. The DICOM JSON file can be created using SaveJson By default, all binary data is read from the DICOM input JSON file, but this behavior can be modified by passing appropriate DicomDataSetLoadJsonFlags

The way that this method processes the input JSON file elements and element values can be customized by passing the optional LoadJsonBeforeElementCallback delegate. For more information on this, see the documentation and example for LoadJsonBeforeElementCallback. The DicomElement themselves can be modified after they have been added to the DicomDataSet by passing the optional LoadJsonAfterElementCallback delegate. For more information on this, see the documentation and example for LoadJsonAfterElementCallback.

Example

This example loads a sample DICOM data set, saves it as JSON to a memory stream (with no binary data), displays the memory stream, reloads the JSON stream into a DicomDataSet object, and saves the DicomDataSet object as a DICOM file

C#
VB
using Leadtools.Dicom; 
using Leadtools.Dicom.Common; 
using Leadtools.Dicom.Common.Extensions; 
using Leadtools; 
using Leadtools.Dicom.Common.Linq.BasicDirectory; 
using Leadtools.Dicom.Common.DataTypes; 
 
public void LoadJsonExample2() 
{ 
   string dicomFileNameIn = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm"); 
   string dicomFileNameOut = Path.Combine(LEAD_VARS.ImagesDir, "test.dcm"); 
 
   // Initialize DICOM engine 
   DicomEngine.Startup(); 
 
   DicomDataSet ds = new DicomDataSet(); 
 
   // Load an existing DICOM file 
   ds.Load(dicomFileNameIn, DicomDataSetLoadFlags.None); 
 
   // Save as JSON to a stream with no binary data 
   // For the demo, keep the json output file size small by skipping the pixel data 
   const DicomDataSetSaveJsonFlags jsonFlags = DicomDataSetSaveJsonFlags.IgnoreBinaryData | DicomDataSetSaveJsonFlags.None | DicomDataSetSaveJsonFlags.TrimWhiteSpace; 
 
   Stream stream = new MemoryStream(); 
   ds.SaveJson(stream, jsonFlags); 
 
   // Display contents of stream 
   stream.Flush(); 
   stream.Position = 0; 
   StreamReader sr = new StreamReader(stream); 
   string jsonString = sr.ReadToEnd(); 
   MessageBox.Show(jsonString, "json version of " + dicomFileNameIn); 
 
   // Now reload the json file from the stream.   
   // Note that there will not be an image because we skipped the pixel data in the save 
   stream.Seek(0, SeekOrigin.Begin); 
   //stream.Position = 0; 
   ds.LoadJson(stream, DicomDataSetLoadJsonFlags.None); 
 
   ds.Save(dicomFileNameOut, DicomDataSetSaveFlags.None); 
 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools.Dicom 
Imports Leadtools.Dicom.Common 
Imports Leadtools.Dicom.Common.Extensions 
Imports Leadtools.Dicom.Common.Linq 
Imports Leadtools.Dicom.Common.Linq.BasicDirectory 
Imports Leadtools 
Imports Leadtools.Dicom.Common.DataTypes 
 
Public Sub LoadJsonExample2() 
   Dim dicomFileNameIn As String = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm") 
   Dim dicomFileNameOut As String = Path.Combine(LEAD_VARS.ImagesDir, "test.dcm") 
 
   ' Initialize DICOM engine 
   DicomEngine.Startup() 
 
   Dim ds As New DicomDataSet() 
 
   ' Load an existing DICOM file 
   ds.Load(dicomFileNameIn, DicomDataSetLoadFlags.None) 
 
   ' Save as JSON to a stream with no binary data 
   ' For the demo, keep the json output file size small by skipping the pixel data 
   Const jsonFlags As DicomDataSetSaveJsonFlags = DicomDataSetSaveJsonFlags.IgnoreBinaryData Or DicomDataSetSaveJsonFlags.None Or DicomDataSetSaveJsonFlags.TrimWhiteSpace 
 
   Dim stream As Stream = New MemoryStream() 
   ds.SaveJson(stream, jsonFlags) 
 
   ' Display contents of stream 
   stream.Flush() 
   stream.Position = 0 
   Dim sr As New StreamReader(stream) 
   Dim jsonString As String = sr.ReadToEnd() 
   MessageBox.Show(jsonString, "json version of " & dicomFileNameIn) 
 
   ' Now reload the json file from the stream.   
   ' Note that there will not be an image because we skipped the pixel data in the save 
   stream.Seek(0, SeekOrigin.Begin) 
   'stream.Position = 0; 
   ds.LoadJson(stream, DicomDataSetLoadJsonFlags.None) 
 
   ds.Save(dicomFileNameOut, DicomDataSetSaveFlags.None) 
 
   DicomEngine.Shutdown() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2019.9.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom.Common Assembly