Skip to content Skip to sidebar Skip to footer

Get The Print Screen Image From The Clipboard

Is there a way to Get the print screen image from the keyboard. Say for example I had a image hosting site and wanted a feature where users could paste in an image and simply host

Solution 1:

It looks like it's going to be possible in HTML 5 using the Canvas element. See this question.

It doesn't seem to be possible in Flash but in Adobe Air. See this question.

Solution 2:

A signed Java applet can access the clipboard.

Take a look at the ClipboardService interface.

The first time the user loads the page they will see a message box asking for permission to access the clipboard.

Update I just discovered that the applet does not need to be signed in order to use the ClipboardService, though the user still sees the warning message the first time.

Solution 3:

No, as far as I know from years of knownledge of Javascript and Flash, this is not possible. Both Flash and JavaScript just don't let you dig deep enough into the system. (Also, I as a user wouldn't like it if they could read my clipboard at will!)

Solution 4:

I have an applet that does exactly this.

User hits print screen, applet copies the image from the clipboard, formats it and uploads to the server.

Here is the class that grabs it from the CB, if you want the rest that formats and uploads to the server let me know.

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;

publicclassImagefromCB
{
// If an image is on the system clipboard, this method returns it;// otherwise it returns null.public Image getImageFromClipboard()
{

    ClipboardsystemClipboard= (Clipboard) AccessController.doPrivileged(newPrivilegedAction() {
        public Object run() 
        {
            ClipboardtempClipboard= Toolkit.getDefaultToolkit().getSystemClipboard();
         return tempClipboard;
        }
    });

    // get the contents on the clipboard in a // Transferable objectTransferableclipboardContents= systemClipboard.getContents(null);

    // check if contents are empty, if so, return nullif (clipboardContents == null)
        returnnull;
    elsetry
        {
            // make sure content on clipboard is // falls under a format supported by the // imageFlavor Flavorif (clipboardContents.isDataFlavorSupported(DataFlavor.imageFlavor))
            {
                // convert the Transferable object// to an Image objectImageimage= (Image) clipboardContents.getTransferData(DataFlavor.imageFlavor);
                return image;
            }
        } catch (UnsupportedFlavorException ufe)
        {
            ufe.printStackTrace();
        } catch (IOException ioe)
        {
            ioe.printStackTrace();
        }
    returnnull;
}

public Image getCBImage()
{
    System.out.println("Copying image from system clipboard.");
    Imageimage= getImageFromClipboard();
    if (image != null)
    {
        return image;
    } else
    {
        System.out.println("No Image found on Clipboard");
        returnnull;
    }
}
}

Solution 5:

Two products that do this is Jira and Youtrack. Both by using a Java Applet. You can use those products GUI as inspiration when making your system. I especially like YouTracks Image from Clipboard Without Preview where you don't need to interact with the applet directly.

Post a Comment for "Get The Print Screen Image From The Clipboard"