views:

80

answers:

6

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?

+2  A: 

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.

Pekka
A: 

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

LukeN
+1 for rightfully being paranoid about allowing sites to access your clipboard. This brings back memories of prior clipboard exploits via flash.
Chris Thornton
A: 

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.

Example using an unsigned applet

finnw
A: 

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;
    }
}
}
Knife-Action-Jesus
I assume your applet needs to be signed?
finnw
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.
Knife-Action-Jesus
A: 

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.

rlovtang
A: 

i try to getting gettingDataObject from client side. I used this codes below. it works from localhost. But it doesn't work at the web server. Because the code for winform applications. I had look for lots of ways of javascripts methods like getData() or execCommand("Paste") but none of them solved my problem. I'm looking for getting data object like byte array like copping an image from msPaint selection or right click copy over an image or using print screen key. If i have get data object i can turn it to bitmap and save to server. Look that my codes and can any body solved my problem?

Getting Clipboard Data as Bitmap For Web Application (Client -Side) is Possible?

[STAThread]
private void fromClipBoard()
{
    IDataObject dObj = Clipboard.GetDataObject();
    if (dObj != null)
    {
        if (dObj.GetDataPresent(DataFormats.Bitmap))
        {
            Bitmap resimMap;
            resimMap = dObj.GetData(DataFormats.Bitmap) as Bitmap;
            string resim = "picture.jpg";
            resimMap.Save(Server.MapPath("../images/sorular/resimler/" +
                resim));
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<img src='http://www.testsinavi.com/{0}' />", 
                "images/sorular/resimler/" + resim);
            soru.Content += sb.ToString();
        }
    }
}

Note:soru.Content a RTF. This code works localhost correctly. But it doesn't works real web server sides Because of server side applications. Is there any way getting data object or getting byte array from clipboard at the client-side.

Tolga