DicomObjects.NET.8.48 Documentation
DicomObjects Namespace / DicomDataSet Class / SetDicomCodec Method
The transfer syntax of the data
The decompressor to use to access the frames etc.
The stream containing the data
Example

In This Topic
    SetDicomCodec Method
    In This Topic
    Specify a "DICOM" codec
    Syntax
    'Declaration
     
    
    Public Sub SetDicomCodec( _
       ByVal TS As UID, _
       ByVal dec As IDecompressor, _
       ByVal Stream As System.IO.Stream _
    ) 
    public void SetDicomCodec( 
       UID TS,
       IDecompressor dec,
       System.IO.Stream Stream
    )

    Parameters

    TS
    The transfer syntax of the data
    dec
    The decompressor to use to access the frames etc.
    Stream
    The stream containing the data
    Example
    // Construct a new DICOM dataset and populate required attributes
    DicomDataSet ds = new DicomDataSet();
                        
    ds.Add(Keyword.Rows, 434);
    ds.Add(Keyword.Columns, 636);
    ds.Add(Keyword.BitsAllocated, 8);
    ds.Add(Keyword.BitsStored, 8);
    ds.Add(Keyword.HighBit, 7);
    ds.Add(Keyword.SamplesPerPixel, 3);
    ds.Add(Keyword.PixelRepresentation, 0); 
    ds.Add(Keyword.PhotometricInterpretation, "RGB");
    ds.Add(Keyword.PlanarConfiguration, 0);     
    ds.Add(Keyword.NumberOfFrames, frames);
                    
    UID transferSyntax = TransferSyntaxes.JPEG2000Lossless;
    IDecompressor myDecompressor = new JpegLosslessDecompressor(); // Implement your own IDecompressor
    Stream pixelData = File.OpenRead("pixeldata.data");
                        
    ds.SetDicomCodec(transferSyntax, myDecompressor, pixelData);
                        
    // Example JpegLosslessDecompressor
                        
    public class JpegLosslessDecompressor : IDecompressor
    {
        public bool NeedsPlanarConfigTransform => false;
        
        public void Decompress(DecompressionArguments args)
        {
            using (var ms = new MemoryStream())
            {
                var srcBytes = new byte[args.SourceStream.Length];
                args.SourceStream.Read(srcBytes, 0, srcBytes.Length);
                using (JpegLSDecoder decoder = new JpegLSDecoder(srcBytes))
                {
                    var decodedBytes = decoder.Decode();
                    Buffer.BlockCopy(decodedBytes, 0, args.DestinationArray, 0, decodedBytes.Length);
                }
            }
        }
        
        public string DecompressedPhotometricInterpretation(DicomObjects.DicomDataSet parent)
        {
            return parent[Keyword.PhotometricInterpretation].Value.ToString(); 
        }
        
        // ETC.
    }
    Requirements

    Target Platforms: .NET CLR 4.8 or higher

    See Also