title: How to save image as DICOM
body: <p>I need to save JPEG image as a DICOM using c# and some free library. I read a lot of topics where it was described how to do the opposite, but I couldn't find anywhere how to perform what I need. The best I could achieve is to save image using ClearCanvas, but it gets distorted. </p>
  
  <pre><code>DicomFile dicomFile = new DicomFile();
  dicomFile.MediaStorageSopClassUid = SopClass.DigitalXRayImageStorageForPresentation.Uid;
  dicomFile.DataSet[DicomTags.SopClassUid].SetStringValue(SopClass.DigitalXRayImageStorageForPresentation.Uid);
  dicomFile.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
  dicomFile.DataSet[DicomTags.ImageType].SetStringValue(@"ORIGINAL\PRIMARY");
  dicomFile.DataSet[DicomTags.Columns].SetInt32(0, width);
  dicomFile.DataSet[DicomTags.Rows].SetInt32(0, height);
  dicomFile.DataSet[DicomTags.BitsStored].SetInt16(0, bitsPerPixel);
  dicomFile.DataSet[DicomTags.BitsAllocated].SetInt16(0, 8);
  dicomFile.DataSet[DicomTags.HighBit].SetInt16(0, 7);
  dicomFile.DataSet[DicomTags.PixelData].Values = imageBuffer;
  dicomFile.Save("e:\\tempFile.dcm");
  </code></pre>
  
  <p>Can anyone please tell me what's wrong with the code above or provide a simple working example on any other free library?</p>