/// <summary>
/// Prints an image box onto the specified graphics.
/// </summary>
/// <param name="imageBox">Image box to print.</param>
/// <param name="graphics">Graphics in which image box should be contained.</param>
/// <param name="box">Rectangle within which the image box should be contained.</param>
/// <param name="imageResolution">Image resolution.</param>
public static void Print(this ImageBox imageBox, Graphics graphics, RectF box, int imageResolution)
{
var state = graphics.Save();
FillBox(imageBox.FilmBox, box, graphics);
var boxCopy = box;
if (imageBox.FilmBox.Trim == "YES")
{
boxCopy.Inflate(-BORDER, -BORDER);
}
if (imageBox.ImageSequence != null && imageBox.ImageSequence.Contains(DicomTag.PixelData))
{
Image bitmap = null;
try
{
var image = new DicomImage(imageBox.ImageSequence);
var frame = image.RenderImage().As<Image>();
bitmap = frame;
DrawBitmap(graphics, boxCopy, bitmap, imageResolution, imageBox.FilmBox.EmptyImageDensity);
}
finally
{
if (bitmap != null)
{
bitmap.Dispose();
}
}
}
graphics.Restore(state);
}