get Image Clipboard - Java Native OS

Java examples for Native OS:Clipboard

Description

get Image Clipboard

Demo 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 {
    public static void main(String[] argv) throws Exception {
        System.out.println(getImageClipboard());
    }/*from w w  w.j av  a2 s. c o m*/

    public static Image getImageClipboard()
            throws UnsupportedFlavorException, IOException {
        Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
            Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
            return image;
        }
        return null;
    }
}

Related Tutorials