Copying The Last Rendered Image To The Windows Clipboard

The following example demonstrates the use of the System.Windows.Forms.Clipboard DotNetClass to read and write bitmaps from/to the Windows Clipboard.

The script can be saved into one of the Startup folders to be evaluated on startup.
The custom function will be executed by a PostRender callback each time the renderer finishes.

fn CopyRenderToClipboard = --define a global function
(
  clipboardClass = dotNetClass "System.Windows.Forms.Clipboard" --create a Clipboard dotNetClass
  b = getLastRenderedImage() --get the last saved image
  theFileName = GetDir #image + "\\_renderToClipboard.bmp" --define a temp.file name
  b.filename = theFileName --set the bitmap's file name
  save b --save the bitmap
  close b --close the bitmap
  theImage = dotNetClass "System.Drawing.Image" --create an Image dotNetClass
  theBitmap = theImage.FromFile theFileName --get the saved image from file as bitmap
  clipboardClass.setImage theBitmap --copy the image to clipboard
  theBitmap.Dispose() --release the bitmap
  deleteFile theFileName --delete the temp. file
  clipboardClass.ContainsImage() --return true if the clipboard contains image
)--end fn

callbacks.removeScripts id:#CopyRenderToClipboard --remove any callbacks with the given ID
callbacks.addScript #PostRender "CopyRenderToClipboard()" id:#CopyRenderToClipboard --register a callback to run the function post-render

 

DotNet Classes Used:
dotNetClass:System.Windows.Forms.Clipboard
dotNetClass:System.Drawing.Image

Last Modified: 2006/10/18