DicomObjects.NET.8.48 Documentation
DicomObjects Namespace / DicomDataSet Class / Write Method / Write(Stream,String,Object) Method

The Stream from which to read.

Specifies the full UID of the transfer syntax with which the data is to be saved when Part 10 format is used. If omitted, the little-endian explicit VR transfer syntax is used.

The quality factor to be used. This is a generic compression quality depending on the Transfer Syntax used. This can be an integer that specifies the value stored in the System.Drawing.Imaging.EncoderParameter object for Bitmap export. This value for JPEG Baseline and JPEG Extended compression represents an integer between 0 – 100. This tells DicomObjects to set up the compressor to try to achieve the quality in percentage (higher quality value towards 100 means better quality and lower compression ratio). And for JPEG-LS Lossy and JPEG2000 Lossy compression this value is actually the desired compression ratio, i.e. if you set the quality value to 10, it tells DicomObjects to try to achieve compression ratio of 10. The actual compression ratio achieved will not be exactly the same as specified by quality value but close enough. The actual compression ratio is calculated based on the original data size and the compressed data size before it is added to “Lossy Image Compression Ratio” tag of the image. For Video compression, this value directly corresponds to the BitsPerSecond of the compressed video.

Example

In This Topic
    Write(Stream,String,Object) Method
    In This Topic
    Writes dataset to a system IO stream object with specified transfer syntax
    Syntax
    'Declaration
     
    
    Public Overloads Sub Write( _
       ByVal Stream As System.IO.Stream, _
       ByVal TransferSyntax As System.String, _
       ByVal Quality As System.Object _
    ) 
    public void Write( 
       System.IO.Stream Stream,
       System.string TransferSyntax,
       System.object Quality
    )

    Parameters

    Stream

    The Stream from which to read.

    TransferSyntax

    Specifies the full UID of the transfer syntax with which the data is to be saved when Part 10 format is used. If omitted, the little-endian explicit VR transfer syntax is used.

    Quality

    The quality factor to be used. This is a generic compression quality depending on the Transfer Syntax used. This can be an integer that specifies the value stored in the System.Drawing.Imaging.EncoderParameter object for Bitmap export. This value for JPEG Baseline and JPEG Extended compression represents an integer between 0 – 100. This tells DicomObjects to set up the compressor to try to achieve the quality in percentage (higher quality value towards 100 means better quality and lower compression ratio). And for JPEG-LS Lossy and JPEG2000 Lossy compression this value is actually the desired compression ratio, i.e. if you set the quality value to 10, it tells DicomObjects to try to achieve compression ratio of 10. The actual compression ratio achieved will not be exactly the same as specified by quality value but close enough. The actual compression ratio is calculated based on the original data size and the compressed data size before it is added to “Lossy Image Compression Ratio” tag of the image. For Video compression, this value directly corresponds to the BitsPerSecond of the compressed video.

    Remarks

    The stream may subsequently be read by the Read method or by other DICOM software.

    Quality is specific to the compression method being used, and is ignored for non-compressed or lossless JPEG transfer syntaxes. For Lossy JPEG, it is an integer in the range 1-100, the higher the number, the better the quality (and the larger the file) , and for JPEG 2000 lossy, it is a compression ratio. Other compression methods may use this for other purposes in the future.

    This method is particularly suitable for use with Delphi, which provides access to streams via classes such as TStreamAdapter.

    Example
    DicomDataSet ds = new DicomDataSet();
    string transferSyntax = TransferSyntaxes.JPEG2000Lossy;
    object quality = 10;
                        
    string pixelTransferSyntax = TransferSyntaxes.ExplicitVRLittleEndian;
    ds.Add(Keyword.SamplesPerPixel, 1);
    ds.Add(Keyword.PhotometricInterpretation, "MONOCHROME2");
    ds.Add(Keyword.Rows, 512);
    ds.Add(Keyword.Columns, 512);
    ds.Add(Keyword.PixelSpacing, new float[] { 0.684f, 0.684f });
    ds.Add(Keyword.BitsAllocated, 16);
    ds.Add(Keyword.BitsStored, 12);
    ds.Add(Keyword.HighBit, 11);
    ds.Add(Keyword.PixelRepresentation, 0);
    ds.Add(Keyword.WindowCenter, new int[] { 35, 50 });
    ds.Add(Keyword.WindowWidth, new int[] { 350, 150 });
    ds.Add(Keyword.RescaleIntercept, -1200);
    ds.Add(Keyword.RescaleSlope, 1);        
    ds.SetPixelData(pixelTransferSyntax, getData);
                        
    using (FileStream fs = new FileStream("Output_Dataset.dcm", FileMode.Create, FileAccess.Write))
    {
        ds.Write(fs, transferSyntax, quality);
    }
                        
    // Method
    private Stream getData(int arg)
    {
        return new FileStream("pixel.data", FileMode.Open, FileAccess.Read, FileShare.Read);
    }
    Requirements

    Target Platforms: .NET CLR 4.8 or higher

    See Also