Copy image to clipboard
It's often desirable to copy the (intermediate) result of a processing sketch to the clipboard for further use in presentations, manuals etc.
To copy the current state of your processing sketch to the clipboard, you can use the following few lines of code:
The ImageSelection class can be found at http://elliotth.blogspot.com/2005/09/copying-images-to-clipboard-with-java.html
If you want to initiate your copy operation by CTRL+C, you can embed the code above inside the keyReleased function:
Please note for cross platform applications, that MacOS uses Alt+C for the same operation.
If you want to clip your image (e.g., omit status bar in your copy), you can also use different width and height coordinates:
// copy (0, 0, otherWidth, otherHeight) region to clipboard BufferedImage clipBoardImage = new BufferedImage(otherWidth, otherHeight, (g.format == ARGB) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB); g.loadPixels(); // important: the last parameter really has to be the original width! clipBoardImage.setRGB(0, 0, otherWidth, otherHeight, g.pixels, 0, width); ImageSelection.copyImageToClipboard(clipBoardImage);