Thank you jeremiah for that demo. Unfortunately it does not work:
procedure TfrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
c: PGtkClipboard;
pixbuf: PGdkPixbuf; {this is a normal pointer}
begin
c := gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
pixbuf := gdk_pixbuf_new_from_file(PChar(UnitClip.aFile), nil);
if Assigned(pixbuf) then
begin
writeln('assigned');
gtk_clipboard_set_image(c, pixbuf);
gtk_clipboard_store(c);
end;
end;
I proceeded this way:
- started the program
- pressed Button 'Clipboard'
- exited the program via the "X" in the upper right corner
- the message 'assigned' was displayed
- checked the clipboard via GIMP, but the clipboard was empty...
- checked that variable 'c' is not nil
Versions: Linux Ubuntu 22.04 with Lazarus 3.4.0 gtk2.
If your demo would work there would be a disadvantage for me, because this way you need a file to read from. In my real project I only have a 'TPicture', which had been loaded from a file some time before and then can be changed in different ways. So there exists no file to load from, only the current contents of a 'TPicture'. Is this possible?
But better would be a
common solution, which reads the *current* graphical content from the clipboard and stores this into a 'pixbuf' (analog to how it is done in unit 'fix_gtk_clipboard' for text contents), because that could be used in any projects.
Can you help?