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");