1
votes

On Linux, I can easily copy an image as PNG data to the clipboard using the clipboard command, which can then be pasted into a graphics program (e.g. GIMP):

set w 300
set h 200
set i [image create photo -width $w -height $h]
$i put blue -to 0 0 $w $h

clipboard clear
clipboard append -type image/png -- [$i data -format png]

image delete $i

However on Windows, this doesn't work; i.e. the clipboard command succeeds, but I cannot paste the image anywhere; also, clipboard monitors (such as http://freeclipboardviewer.com/) don't show any copied content.

Is there anything wrong with -type image/png? Should I use a different -type parameter or even a different data format (e.g. BMP, JPEG)?

Can this be done with "native" Tcl/Tk commands (without using twapi as suggested in https://wiki.tcl-lang.org/page/Copy+image+to+and+from+the+Windows+clipboard)?

1
Clipboard formats work utterly differently on Windows and Linux (well, X11) and you've found out where you reach beyond the point that the code hides the details from you. Which doesn't help you do anything about it…Donal Fellows
PNG is a file format, invented long after Windows had a clipboard. Odds that any native Win program can recognize it are quite low. Standard is BMP and (less) DIB.Hans Passant
@HansPassant that's correct. I'm actually not that fixed on PNG - I would also be happy for a solution that copies BMP/DIB data to the clipboard (preferably using standard Tcl/Tk commands) => I will update the questionFlopp
@han: Windows has been shipping a PNG encoder and decoder for more than decade. It's part of WIC's standard codecs.IInspectable

1 Answers

1
votes

Short anwser. You can't. I guess you best/only option is twapi.

The tk's clipboard command on Windows works for text only. As you can read in the source file of windows's clipboard there are not options for images, just for text.