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?
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
精彩评论