DicomObjects.NET.8.48 Documentation
DicomObjects Namespace / DicomDataSet Class / AddPixelData Method

The Byte Array to be added to the Pixel Attribute (7FE0, 0010) of the DataSet

Specifies the UID of the transfer syntax in which the data is coded. If omitted, the little-endian explicit VR transfer syntax is used.

Example

In This Topic
    AddPixelData Method
    In This Topic
    Adds pixel data to DicomDataSet
    Syntax
    'Declaration
     
    
    Public Sub AddPixelData( _
       ByVal Data As System.Object, _
       ByVal TransferSyntax As System.String _
    ) 
    public void AddPixelData( 
       System.object Data,
       System.string TransferSyntax
    )

    Parameters

    Data

    The Byte Array to be added to the Pixel Attribute (7FE0, 0010) of the DataSet

    TransferSyntax

    Specifies the UID of the transfer syntax in which the data is coded. If omitted, the little-endian explicit VR transfer syntax is used.

    Remarks
    This method overwrites the pixel data (if present) in the DicomDataSet object.
    Example
    DicomDataSet ds = new DicomDataSet();
                        
    //  add all relevant group 28 attributes to image to tell DicomObjects how to display
    ds.Add(Keyword.SamplesPerPixel, 1);
    ds.Add(Keyword.Rows, 512);
    ds.Add(Keyword.Columns, 512);
    ds.Add(Keyword.PixelSpacing, new float[] { 0.684f, 0.684f });
    ds.Add(Keyword.BitsAllocated, 8);
    ds.Add(Keyword.BitsStored, 8);
    ds.Add(Keyword.HighBit, 7); 
    ds.Add(Keyword.PixelRepresentation, 0); // PixelRepresentation 0=unsigned,1=signed
                        
    if (Convert.ToInt16(ds[Keyword.SamplesPerPixel].Value) == 1)
    {
        ds.Add(Keyword.PhotometricInterpretation, "MONOCHROME2"); 
    }
    else if (Convert.ToInt16(ds[Keyword.SamplesPerPixel].Value) == 3)
    {
        ds.Add(Keyword.PhotometricInterpretation, "RGB");
        ds.Add(Keyword.PlanarConfiguration, 0);
    }
                        
    ds.Add(Keyword.WindowCenter, new int[] { 35, 50 });
    ds.Add(Keyword.WindowWidth, new int[] { 350, 150 });
                        
    byte[] pixelBytes = File.ReadAllBytes("RawPixelData.raw");
    string ExplicitVRLittleEndian = "1.2.840.10008.1.2.1";
    ds.AddPixelData(pixelBytes, ExplicitVRLittleEndian);
     
    (Optionally) write it to file
    ds.Write(@"path\to\save\location\dataset.dcm");
    Requirements

    Target Platforms: .NET CLR 4.8 or higher

    See Also