Java Clipboard Image setClipboardImage(final Image image)

Here you can find the source of setClipboardImage(final Image image)

Description

Write the specified image to system clip board.

License

Open Source License

Parameter

Parameter Description
image the specified image to write

Declaration

public static void setClipboardImage(final Image image) 

Method Source Code


//package com.java2s;
import java.awt.Image;
import java.awt.Toolkit;

import java.awt.datatransfer.DataFlavor;

import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

import java.io.IOException;

public class Main {
    /**//from w ww  . j  a  v  a  2s.  c o  m
     * Write the specified image to system clip board.
     * 
     * @param image
     *            the specified image to write
     */
    public static void setClipboardImage(final Image image) {
        Transferable trans = new Transferable() {
            public DataFlavor[] getTransferDataFlavors() {
                return new DataFlavor[] { DataFlavor.imageFlavor };
            }

            public boolean isDataFlavorSupported(DataFlavor flavor) {
                return DataFlavor.imageFlavor.equals(flavor);
            }

            public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
                if (isDataFlavorSupported(flavor))
                    return image;
                throw new UnsupportedFlavorException(flavor);
            }
        };
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trans, null);
    }
}

Related

  1. getClipboardImage()
  2. getClipboardImage()
  3. getFilenameFromClipboard(Clipboard clip)
  4. isImageDataFlavor(Clipboard clip)
  5. setClipboardImage(final Image image)