Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you copy a PNG image to the clipboard using Delphi

Using Delphi 2010 I would like to copy a PNG image to the clipboard while preserving the alpha transparency. Unfortunately, the TPngImage.SaveToClipboardFormat method will draw it to a bitmap and the transparency will be lost.

I would like for the PNG image to be pasted in applications such as Photoshop and Word with alpha transparency.

Any idea on how to do that ? How are other applications doing to copy transparency in the clipboard ?

like image 621
jonjbar Avatar asked Feb 16 '10 08:02

jonjbar


3 Answers

I'd first copy an image with transparency information to the clipboard in Photoshop, and then examine what's actually on the clipboard. When you know this, you can probably figure out how to write that data yourself.

like image 161
Frederik Slijkerman Avatar answered Sep 22 '22 19:09

Frederik Slijkerman


With delphi XE, all i did was:

Clipboard.Assign(Image1.Picture.Graphic);
like image 37
X-Ray Avatar answered Sep 21 '22 19:09

X-Ray


It could be that they use an alternative clipboard format, see http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx for a list of available clipboard formats. Or they could register their own clipboard format such as

RegisterClipboardFormat('PNG') 

and then simply write the png data to the clipboard. If the clipboard format string specified is standard (i.e. other applications register the same clipboard format) then you will be able to paste it into other applications which support this clipboard format.

You might need to call windows functions directly as Delphi's clipboard wrapper isn't very good.

like image 35
James Barrass Avatar answered Sep 23 '22 19:09

James Barrass