GNOME 剪贴板是否具有与数据关联的 MIME 类型?

发布于 2024-10-08 02:06:55 字数 968 浏览 0 评论 0原文

我知道Linux中有几种类型的选择primarysecondaryclipboard,我处理前两种作为短期剪贴板,clipboard 作为长期剪贴板。我说得对吗?

现在,由于primary/secondary 选择仅包含文本,我想将图像复制到long-term 剪贴板,但我不这样做了解是否存在与其关联的 MIME 类型。因为Screen Capture能够将屏幕截图复制到剪贴板,所以我猜想有一些元数据来描述它的图像格式。但是像xsel这样的命令没有提供任何操作图像剪贴板数据的选项。既不支持将图像文件复制到剪贴板,也不支持将图像从剪贴板转储到文件。

搜索google后,我发现Python/Gtk有一些支持:

import pygtk
pygtk.require('2.0')
import gtk
import os
def copy_image(f):
    assert os.path.exists(f), "file does not exist"
    clipboard = gtk.clipboard_get()
    img = gtk.Image()
    img.set_from_file(f)
    clipboard.set_image(img.get_pixbuf())
    clipboard.store()

我自己没有尝试过,因为我对Python不熟悉,但看起来至少有一些程序支持图像剪贴板。

这里有一个问题,因为我猜 GNOME 中的剪贴板可能没有 MIME 类型,所以大多数 Gnome 应用程序在图像格式上共享相同的约定吗?

另外,如果我想使用图像剪贴板进行编程以在不同应用程序之间共享图像,例如一个想要8位索引位图,另一个想要24位RGB位图,我应该参考哪些文档?

I know there's several type of selection in Linux: primary, secondary, and clipboard, I treat the first two as short-term clipboard, and clipboard as long-term clipboard. Am I right?

Now, since the primary/secondary selection is text-only, I want to copy image to the long-term clipboard, I don't know if there is a MIME type associated with it. Because the Screen Capture is able to copy the screenshot to clipboard, so I guess there is some meta data to describe it's in image format. But commands like xsel doesn't give any option on operating image clipboard data. Neither copy image file to clipboard nor dump the image from clipboard to file is supported.

After search the google, I found there's some support in Python/Gtk:

import pygtk
pygtk.require('2.0')
import gtk
import os
def copy_image(f):
    assert os.path.exists(f), "file does not exist"
    clipboard = gtk.clipboard_get()
    img = gtk.Image()
    img.set_from_file(f)
    clipboard.set_image(img.get_pixbuf())
    clipboard.store()

I haven't tried it myself, because I'm not familiar with Python, but that look like at least some programs support the image clipboard.

Here is a question, since I guess the clipboard in GNOME may not have a MIME type, does most of Gnome applications share the same convention on image format?

And, what documents shall I refer to if I want to program with image clipboard to share images between different applications, for example one want 8-bit indexed bitmap and another want 24-bit RGB bitmap?

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

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

发布评论

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

评论(1

煮酒 2024-10-15 02:06:55

复制& Gnome 中的粘贴执行协商数据传输,一个提供可用于数据的格式列表,另一个选择其首选类型。 Gtk+ 等 API 只为 GdkPixbuf 提供接口并管理格式传输本身,从而简化了这一过程。

通常您不需要原始位图传输,因为对于大图像来说它会相当慢,PNG 压缩很好,但粘贴到 OO.o 仅支持 JPEG 压缩,您通常不希望用于非照片对象。这会导致从 The Gimp 到 Writer 的图像粘贴速度缓慢。

http://library.gnome.org/devel/gtk/stable/gtk -Clipboards.html

Copy & paste in Gnome performs a negotiated data transfer, one provides a list of formats available for the data and the other chooses their preferred type. APIs such as Gtk+ simplify this by only providing an interface for a GdkPixbuf and managing the format transfer itself.

Usually you are not wanting a raw bitmap transfer as it is going to be rather slow for large images, PNG compression is good but say pasting to OO.o only supports JPEG compression which you usually do not want for non-photo objects. This leads to slow pasting of images from say The Gimp to Writer.

http://library.gnome.org/devel/gtk/stable/gtk-Clipboards.html

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