从剪贴板获取打印屏幕图像

发布于 2024-09-09 10:06:30 字数 162 浏览 5 评论 0 原文

有没有办法从键盘获取打印屏幕图像。举例来说,我有一个图像托管网站,想要一个功能,用户可以粘贴图像并以这种方式简单地托管它。这可能吗?

抱歉,这是一个如此模糊的问题。

编辑:是否可以使用某种第三方插件?是否有任何现有的 Firefox 插件可以执行类似的操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

美羊羊 2024-09-16 10:06:30

看起来将会在 HTML 5 中使用 Canvas 元素成为可能。请参阅这个问题。

这在Flash中似乎不可能,但在Adobe Air中是不可能的。请参阅此问题

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.

半葬歌 2024-09-16 10:06:30

签名 Java 小程序可以访问剪贴板。

看一下 ClipboardService 接口。

用户第一次加载页面时,他们将看到一个消息框,请求访问剪贴板的权限。

更新我刚刚发现小程序不需要需要签名才能使用ClipboardService,尽管用户仍然会看到警告消息第一次。

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.

神经暖 2024-09-16 10:06:30

不,据我多年来对 Javascript 和 Flash 的了解,这是不可能的。 Flash 和 JavaScript 都不允许您深入了解系统。 (另外,如果他们可以随意读取我的剪贴板,我作为用户不会喜欢它!)

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

凹づ凸ル 2024-09-16 10:06:30

我有一个小程序可以做到这一点。

用户点击打印屏幕,小程序从剪贴板复制图像,对其进行格式化并上传到服务器。

这是从 CB 获取它的类,如果您想要其余部分格式化并上传到服务器,请告诉我。

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;
    }
}
}

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;
    }
}
}
离旧人 2024-09-16 10:06:30

执行此操作的两个产品是 JiraYoutrack。两者都使用 Java Applet。
您可以在制作系统时使用这些产品 GUI 作为灵感。
我特别喜欢 YouTracks 剪贴板中的图像,无需预览,您无需这样做直接与小程序交互。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文