Making a copy of the image as displayed

In order to use PrinterImage to make a complete copy of the image as displayed in the viewer, it is necessary to:

  1. Use a recent copy of DicomObjects (copies prior to 5.6.116.x had a bug in the label handling which distorted images)
  2. Calculate the size of the area being displayed
  3. Find the actual zoom of the image as currently displayed
  4. Scale the current size up to the equivalent in image units (divide by zoom)
  5. Likewise scale the image's Offset to create correct position for the image in the new rectangle
  6. Call PrinterImage

Note that the zoom used int he final PrinterImage call does not need to be the same as used above, and a higher quality output can be obtained by setting it to 1 (or higher to allow DicomOBjects to do any interpolation), but that you may wish to modify the font size of any labels to compensate.


Dim im As DicomImage = viewer.CurrentImage
Dim sz As SizeF  ' display image area in screen pixels
If im.Area = RectangleF.Empty Then  ' not using area
  sz = New SizeF(viewer.Width / viewer.MultiColumns, viewer.Height / viewer.MultiRows)
  sz = New SizeF(viewer.Width * im.Area.Width, viewer.Height * im.Area.Height)
End If

Dim m As System.Drawing.Drawing2D.Matrix = im.Matrix(viewer)
Dim zoom As Single = DicomGlobal.Zoom(m)
'Convert size to image coordinates
sz = New SizeF(sz.Width / zoom, sz.Height / zoom)

' make offset to put image in correct location
Dim Offset As Point = New Point(-im.Scroll.X / zoom, -im.Scroll.Y / zoom)
Dim Canvas As Rectangle = New Rectangle(Offset, Size.Truncate(sz))

Dim FinalCopy as DicomImage = viewer.CurrentImage.PrinterImage(8, 1, True, zoom, Canvas, True)

In C#

DicomImage im = viewer.CurrentImage;
SizeF sz;  // display image area in screen pixels
if(im.Area == RectangleF.Empty) // not using area
  sz = new SizeF(viewer.Width / viewer.MultiColumns, viewer.Height / viewer.MultiRows);
  sz = new SizeF(viewer.Width * im.Area.Width, viewer.Height * im.Area.Height);

System.Drawing.Drawing2D.Matrix m = im.Matrix(viewer);
float zoom = DicomGlobal.Zoom(m);

// Convert size to image coordinates
sz = new SizeF(sz.Width / zoom, sz.Height / zoom);

// make offset to put image in correct location
Point Offset = New Point(-im.Scroll.X / zoom, -im.Scroll.Y / zoom);
Rectangle Canvas = New Rectangle(Offset, Size.Truncate(sz));

DicomImage FinalCopy = viewer.CurrentImage.PrinterImage(8, 1, true, zoom, Canvas, true);