A strongly typed ADO.NET
DataTable which contains the information about the DICOM images.
Syntax
Example
Visual Basic |
Copy Code |
<Test> _ Public Sub StoreDICOMImages() Dim dataSet As DicomDataSet = New DicomDataSet() Dim dataSetPath As String = Path.Combine (ImagesPath.Path, "IMAGE1.DIC")
dataSet.Load (dataSetPath, DicomDataSetLoadFlags.LoadAndClose)
Dim thumbnailPath As String = GenerateThumbnail (dataSet)
Dim dataAccessAgent As IWorkstationDataAccessAgent = Nothing Try dataAccessAgent = DataAccessAgentFactory.Instance.CreateAccessAgent ("WorkstationSqlCeConnection")
If Nothing Is dataAccessAgent Then Console.WriteLine ("You have not configured a valid database connection.")
Return End If Catch exception As Exception Console.WriteLine(exception.Message," :You have not configured a valid database connection.")
Return End Try
dataAccessAgent.AddDicom (dataSet, "TEST", dataSetPath,thumbnailPath)
Dim queryResult As DicomInformation = dataAccessAgent.QueryDicomInformation (New FindQuery ())
If queryResult.Images.Count > 0 Then Console.WriteLine (queryResult.Images (0).SOPInstanceUID)
dataAccessAgent.RemoveDicom (queryResult.Images) Else Console.WriteLine ("No images found in the database.") End If End Sub
Private Function GenerateThumbnail(ByVal dataset As DicomDataSet) As String Dim codec As RasterCodecs = New RasterCodecs()
Dim imageElement As DicomElement = dataset.FindFirstElement(Nothing, DicomTag.PixelData, False)
If Not Nothing Is imageElement Then Dim rasterImage As RasterImage Dim resizeCmd As SizeCommand Dim thumbImage As String
rasterImage = dataset.GetImage(imageElement, 0, 0, RasterByteOrder.Rgb, DicomGetImageFlags.AutoApplyModalityLut Or DicomGetImageFlags.AutoApplyVoiLut)
If rasterImage.Signed OrElse rasterImage.GrayscaleMode = RasterGrayscaleMode.OrderedInverse Then Dim cmgGray As GrayscaleCommand
cmgGray = New GrayscaleCommand(8)
cmgGray.Run(rasterImage) End If
resizeCmd = New SizeCommand(64, 64, RasterSizeFlags.None)
resizeCmd.Run(rasterImage)
thumbImage = Path.Combine (ImagesPath.Path, "Test.jpg")
codec.Save(rasterImage, thumbImage, RasterImageFormat.Jpeg, 24)
Return thumbImage Else Return Nothing End If End Function |
C# |
Copy Code |
public void StoreDICOMImages ( ) { DicomDataSet dataSet = new DicomDataSet(); string dataSetPath = Path.Combine ( ImagesPath.Path, "IMAGE1.DIC" ) ; dataSet.Load ( dataSetPath, DicomDataSetLoadFlags.LoadAndClose ) ; string thumbnailPath = GenerateThumbnail ( dataSet ) ; IWorkstationDataAccessAgent dataAccessAgent = null ; try { //make sure you have configured the application configuration file with a valid //SqlCe connection string which have the same connection name 'WorkstationSqlCeConnection' dataAccessAgent = DataAccessAgentFactory.Instance.CreateAccessAgent ( "WorkstationSqlCeConnection" ) ; if ( null == dataAccessAgent ) { Console.WriteLine ( "You have not configured a valid database connection." ) ; return ; } } catch ( Exception exception ) { Console.WriteLine( exception.Message," :You have not configured a valid database connection."); return ; } dataAccessAgent.AddDicom ( dataSet, "TEST", dataSetPath,thumbnailPath ) ; //perform a wildcard query for all the database information. DicomInformation queryResult = dataAccessAgent.QueryDicomInformation ( new FindQuery ( ) ) ; if ( queryResult.Images.Count > 0 ) { Console.WriteLine ( queryResult.Images [ 0 ].SOPInstanceUID ) ; dataAccessAgent.RemoveDicom ( queryResult.Images ) ; } else { Console.WriteLine ( "No images found in the database." ); } } private string GenerateThumbnail ( DicomDataSet dataset ) { RasterCodecs codec = new RasterCodecs(); DicomElement imageElement = dataset.FindFirstElement(null, DicomTag.PixelData, false); if (null != imageElement) { RasterImage rasterImage; SizeCommand resizeCmd; string thumbImage; rasterImage = dataset.GetImage(imageElement, 0, 0, RasterByteOrder.Rgb, DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut); if (rasterImage.Signed || rasterImage.GrayscaleMode == RasterGrayscaleMode.OrderedInverse) { GrayscaleCommand cmgGray; cmgGray = new GrayscaleCommand(8); cmgGray.Run(rasterImage); } resizeCmd = new SizeCommand(64, 64, RasterSizeFlags.None); resizeCmd.Run(rasterImage); thumbImage = Path.Combine ( ImagesPath.Path, "Test.jpg" ) ; codec.Save(rasterImage, thumbImage, RasterImageFormat.Jpeg, 24); return thumbImage ; } else { return null ; } } |
Remarks
Inheritance Hierarchy
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also