Below is the method I have for taking the image turning it into a bitmap and creating the dicom pixel data, Before this method is called the Dataset has been populated with data on a patient and procedure and this is the final stage before outputing the file.
Hope this is of some use
private void ProcessImage(byte[] imageBytes)
{
Bitmap bmp;
int rows, columns;
var bitmapUtils = new BitmapUtils();
using(var ms = new MemoryStream())
{
ms.Write(imageBytes, 0, imageBytes.Length);
ms.Seek(0L, SeekOrigin.Begin);
bmp = new Bitmap(Image.FromStream(ms));
}
var pixelData = DicomPixelData.Create(data, true); //data is my DicomDataset
pixelData.HighBit = 7;
pixelData.BitsStored = 8;
pixelData.BitsAllocated = 8;
pixelData.SamplesPerPixel = 3;
pixelData.PlanarConfiguration = 0;
pixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb;
pixelData.PixelRepresentation = 0;
pixelData.Height = (ushort)bmp.Height;
pixelData.Width = (ushort)bmp.Width;
byte[] uncompressedBitmapByteArray = bitmapUtils.GetPixelData(bmp, out rows, out columns);
//below was the what I thought I had to do to get the image to the pixeldata imo this is where the problem may be
using (var ms = new MemoryStream())
{
ms.Read(uncompressedBitmapByteArray, 0, uncompressedBitmapByteArray.Length);
ms.Seek(0L, SeekOrigin.Begin);
var s = new StreamByteSource(ms);
pixelData.AddFrame(s.GetBuffer((uint)ms.Length));
}
}