3

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 it that way. would that be possible?

Sorry this is such a vague question.

EDIT: Would it be possible with some sort of third party plugin? Are there any existing Firefox plugins which do something similar?

5 Answers 5

2

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.

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.

0

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!)

1
  • +1 for rightfully being paranoid about allowing sites to access your clipboard. This brings back memories of prior clipboard exploits via flash. Jul 16, 2010 at 17:25
0

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;

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

    Clipboard systemClipboard = (Clipboard) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() 
        {
            Clipboard tempClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
         return tempClipboard;
        }
    });

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

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

public Image getCBImage()
{
    System.out.println("Copying image from system clipboard.");
    Image image = getImageFromClipboard();
    if (image != null)
    {
        return image;
    } else
    {
        System.out.println("No Image found on Clipboard");
        return null;
    }
}
}
2
  • I assume your applet needs to be signed?
    – finnw
    Jul 31, 2010 at 19:22
  • Yes, Not sure if there is a way to use the AccessController without the having a signed applet, I believe without signing the applet you are stuck in sandbox permissions, unless you edit the policy file on the client machine which is bad practice.
    – Keibosh
    Aug 2, 2010 at 16:44
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.