Fairly simple, I would like to copy an image into the system clipboard using java and be able to past what is currently in the clipboard into another application, such as word, google docs, etc. etc.
At the moment I've found the common
public static void setClipboard(Image image)
{
ImageTransferable imgSel = new ImageTransferable(image);
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents(imgSel, null);
}
static class ImageTransferable implements Transferable
{
private Image image;
public ImageTransferable (Image image)
{
this.image = image;
}
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException
{
if (isDataFlavorSupported(flavor))
{
return image;
}
else
{
throw new UnsupportedFlavorException(flavor);
}
}
public boolean isDataFlavorSupported (DataFlavor flavor)
{
return flavor == DataFlavor.imageFlavor;
}
public DataFlavor[] getTransferDataFlavors ()
{
return new DataFlavor[] { DataFlavor.imageFlavor };
}
}
Unfortunately this does not put the image into a clipboard in a paste-able state outside of the java program itself. I can get it to successfully pull from the clipboard (c) to paste the image programmatically in the java program itself but not into another window or application.