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 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?
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.
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.
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!)
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;
}
}
}
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.
精彩评论