How To > Use DotNet > Copy The Last Rendered Image To The Windows Clipboard |
The following tutorial demonstrates the use of the System.Windows.Forms.Clipboard DotNetClass to read and write bitmaps from and 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, putting the last rendered image into the Windows Clipboard automatically.
dotNetClass:System.Windows.Forms.Clipboard
Define a global function. We will place the script in a startup folder, so we want the function to be visible in the global scope.
Get the Clipboard dotNetClass from System.Windows.Forms
Set the bitmap's file name to the one defined in the previous step.
Save the bitmap to disk under the assigned file name.
Get the Image dotNetClass from System.Drawing
Get the saved image from file as bitmap
Copy the image to the clipboard by calling the setImage method exposed by the clipboard class.
Release the bitmap - it is already in the Windows Clipboard!
Delete the temporary file from disk.
Return true if the Windows Clipboard contains an image, which we can assume is our image.
This is the end of the global function.
Now we will register a general callback to call the function whenever the renderer finishes.
First we make sure we remove any callbacks with the same ID as the one we are about to register. This way, you can run the script multiple times (for example while further developing the function or making changes to the code in general).
Then we register a PostRender callback to run the function whenever the renderer finishes.