Get image form system clip board. - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

Get image form system clip board.

Demo Code

/*// w ww. j a  va 2  s. c om
 * Copyright (c) 2011, 2020, Frank Jiang and/or its affiliates. All rights
 * reserved.
 * SystemUtils.java is built in 2013-2-14.
 */
//package com.java2s;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;

import java.awt.datatransfer.Transferable;

public class Main {
    /**
     * Get image form system clip board.
     * 
     * @return the image
     * @throws Exception
     */
    public static Image getImageFromClipboard() throws Exception {
        Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable cc = sysc.getContents(null);
        if (cc == null)
            return null;
        else if (cc.isDataFlavorSupported(DataFlavor.imageFlavor))
            return (Image) cc.getTransferData(DataFlavor.imageFlavor);
        return null;
    }
}

Related Tutorials