Hi Alex
Unfortunately DICOM format requires each frame to be both the same size and pixel format. So if you are receiving the "different images" error, one or more of the following has changed between frames:
- Bitmap.Width
- Bitmap.Height
- Bitmap.Params.BitsPerSample
- Bitmap.Params.SamplesPerPixel
The following code works if all source images have matching size and pixel format properties:
procedure TForm1.Button1Click(Sender: TObject);
var
bmpM: TIEMultiBitmap;
bmp : TIEBitmap;
i: Integer;
begin
bmpM := TIEMultiBitmap.Create;
bmpM.ParamsEnabled := True;
for i := 0 to sl.count-1 do
begin
bmp := TIEBitmap.Create();
bmp.ParamsEnabled := True;
bmp.Read(sl[i]);
bmpM.AppendImage(bmp);
bmp.Free;
end;
bmpM.Write( 'D:\multidicom.dcm', ioDICOM );
bmpM.Free;
end;
In your case, you might want to iterate through each frame, updating the pixel format, BitsPerSample and SamplesPerPixel, and if necessary, the size.
Here is an example of that:
procedure TForm1.Button1Click(Sender: TObject);
var
mbmp: TIEMultiBitmap;
mio: TImageEnMIO;
bmp : TIEBitmap;
i: Integer;
begin
mbmp := TIEMultiBitmap.create;
mio := TImageEnMIO.CreateFromIEMBitmap(mbmp);
for i := 0 to sl.count-1 do
begin
bmp := TIEBitmap.Create();
bmp.ParamsEnabled := True;
bmp.Read(sl[i]);
mbmp.AppendImage(bmp);
bmp.Free;
end;
// Ensure all frames of DICOM are same size
for I := 1 to mbmp.Count - 1 do
begin
bmp := mbmp.GetTIEBitmap( I );
bmp.Resample( mbmp.ImageWidth[0], mbmp.ImageHeight[0], rfFastLinear );
mbmp.ReleaseBitmap( I, True );
end;
// Ensure all frames of DICOM have same duplication and pixel format info
mio.DuplicateCompressionInfo();
mio.SaveToFileDICOM( 'D:\multidicom3.dcm' );
mio.Free;
mbmp.free;
end;
Nigel
Xequte Software
www.imageen.com