Thanks Michael, actually I've made some advances.
First of all, when I call getOutputData I must explicitly set the parameter bits, for example getOutputData(8).
Then, before calling putAndInsertUint8Array I have to set image parameters as follows
Code: Select all
lDataset->putAndInsertUint16(DCM_SamplesPerPixel, 1);
lDataset->putAndInsertString(DCM_PhotometricInterpretation, "MONOCHROME2");
lDataset->putAndInsertUint16(DCM_Rows, cols);
lDataset->putAndInsertUint16(DCM_Columns, rows);
lDataset->putAndInsertUint16(DCM_BitsAllocated, 8);
lDataset->putAndInsertUint16(DCM_BitsStored, 8);
lDataset->putAndInsertUint16(DCM_HighBit, 7);
lDataset->putAndInsertUint16(DCM_PixelRepresentation, 0);
lDataset->putAndInsertUint8Array(DCM_PixelData, (const Uint8 *)buffer, rows * cols);
With this code, I come to this image (not perfect but near):
All dcmtk code is running in a shared library loaded from a FreePascal program in charge of loading the pixeldata into a 256 color palette canvas, adding the text, then copy the modified canvas to the buffer, and sending back the buffer to the shared library to save the new dicom image.
Before sending the buffer to the shared library, if I save the canvas as a bmp, I get this:
That's the final result I want to get in my Dicom image.
Any hint?, do you see something wrong in my code, maybe the palette I'm using is not correct?.
Thanks in advance.