Navigation:  I Want To... > Imaging >

Render to a bitmap

Previous pageReturn to chapter overviewNext page

Use Cases

You want to render an image to a .NET bitmap.  Uses of the bitmap might include, for example, thumbnail and DICOM secondary image generation.

Relevant Architecture

The rendering object model
Inside a renderer
How rendering is triggered

Relevant Types

IPresentationImage
PresentationImage

Sample Code

using System.Drawing;

using System.Drawing.Imaging;

using ClearCanvas.Common;

using ClearCanvas.Desktop;

using ClearCanvas.Desktop.Actions;

using ClearCanvas.ImageViewer;

using ClearCanvas.ImageViewer.BaseTools;

 

// ... (other using namespace statements here)

 

namespace MyPlugin.Imaging

{

   [ButtonAction("apply""global-toolbars/ToolbarStandard/RenderToBitmapTool""Apply")]

   [IconSet("apply", IconScheme.Colour, "Icons.MyToolSmall.png""Icons.MyToolMedium.png""Icons.MyToolLarge.png")]

   // ... (other action attributes here)

   [ExtensionOf(typeof (ImageViewerToolExtensionPoint))]

   public class RenderToBitmapTool : ImageViewerTool

   {

      public void Apply()

      {

         if (this.SelectedPresentationImage == null)

            return;

 

         Bitmap bitmap = this.SelectedPresentationImage.DrawToBitmap(500600);

         bitmap.Save("MyImage.png", ImageFormat.Png);

         bitmap.Dispose();

      }

   }

}

Remarks

Sometimes you want to render to a memory bitmap so you can use the result in some other context. For example, when generating thumbnails, you may want to use the resulting thumbnail bitmaps in a list control.  Or when generating a secondary capture DICOM image, you may want to use the resulting bitmap as a basis for generating the DICOM pixel data.

Examples in Code Base

ClearCanvas.ImageViewer.Thumbnails.ThumbnailComponent
ClearCanvas.ImageViewer.Clipboard.IconCreator