Copy an image (png file) to the clipboard

385 views
Skip to first unread message

CV

unread,
Sep 10, 2025, 8:29:00 PM (10 days ago) Sep 10
to Harbour Users
Hi

In an application I'm developing, I need to copy a given image file (it is in .PNG format) to the clipboard 
I don't need the name of the file, just its content so the user can paste it in another application, like Word or an email message.

I wish to know if there is a way to do that under harbour (it is a console mode application).
Some hints will be great!

Regards
--
Claudio Voskian
Buenos Aires - Argentina

RyszardR

unread,
Sep 11, 2025, 7:29:28 AM (9 days ago) Sep 11
to Harbour Users
IrfanView
i_view32.exe c:\test.jpg /clipcopy /killmesoftly

CV

unread,
Sep 11, 2025, 8:43:45 AM (9 days ago) Sep 11
to Harbour Users
Hi RyszardR!

Thank you for the information, I will use this but I need to integrate this functionality by code into the application, that is by prg or c-code or a library, to avoid installing / copying this in the client setup.

Regards!
©
Message has been deleted

pete....@gmail.com

unread,
Sep 11, 2025, 11:35:53 AM (9 days ago) Sep 11
to Harbour Users
Hi, 
there is a gdImageCopy***() series of functions included into hbgd contrib library.
(I 've never used this library, but you may want to give it a try...) 

CV

unread,
Sep 11, 2025, 2:21:54 PM (9 days ago) Sep 11
to Harbour Users
Hi Pete

Thank you for your response. 

This library is not generated automatically when I built my harbour release, as it depends on the existence of the library to which it tries to wrap on.
As I don't know what to do to build it, I can't use it directly.
Anyway, I inspected the code in the contrib\hbgd folder and there is no mention to the clipboard.

I think that one possible way is to display the image on a separate window and in some way make a copy of the window to the clipboard.
Harbour has only a way to copy the clipboard for text, so by now I can't make an image copy.

Regards!
©

marcos...@gmail.com

unread,
Sep 11, 2025, 6:01:52 PM (9 days ago) Sep 11
to Harbour Users
Hello

I'm attaching an example of how to transfer an image to Clipboard.

Best regards

Marcos
image_2.prg

CV

unread,
Sep 13, 2025, 10:24:35 AM (7 days ago) Sep 13
to Harbour Users
Hi Marcos!

Thank you for the code, as far as I can see it is suited for Minigui. 
I'm using xharbour or harbour, so I can't use it directly but will try to adapt it to my needs.

Regards
©

Daniele Campagna

unread,
Sep 14, 2025, 9:46:39 AM (6 days ago) Sep 14
to harbou...@googlegroups.com

To manage the Windows clipboard, you need a call to a Windows API (while to access an image you don't need necessarily any Window API call.) To manage Windows API calls, Harbour has the hbwin lib, but I wasn't able to find the clipboard management.

So you have to resort to some library like HMG, MiniGui or whatever, able to access Windows APIs and the clipboard. 

As a bonus, the two mentioned libs can also manage images via the BosTaurus library (included).

AND both Minigui and HMG (the ancestor) can run directly a console program. I don't know if other libraries can do that, maybe GTWVW, GTWVG and GTWVT.

Dan

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/c7ffc8e1-2b93-447b-a15b-fdc011a85574n%40googlegroups.com.

RyszardR

unread,
Sep 17, 2025, 1:51:50 AM (3 days ago) Sep 17
to Harbour Users
Maybe  using powershell ?

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$pngPath = "C:\images\test.png"
$image = [System.Drawing.Image]::FromFile($pngPath)
[System.Windows.Forms.Clipboard]::SetImage($image)

RyszardR

unread,
Sep 18, 2025, 4:57:50 AM (2 days ago) Sep 18
to Harbour Users
Or simply:

procedure image2clip(plik)
local ws,pscmd,cmd
pscmd:="cABhAHIAYQBtAA0ACgAoAA0ACgAgACAAIAAgAFsAUABhAHIAYQBtAGUAdABlAHIAKABNAGEAbgBkAGEAdABvAHIAeQApAF0ADQAKACAAIAAgACAAWwBzAHQAcgBpAG4AZwBdAA0ACgAgACAAIAAgACQAaQBtAGcAZgBpAGwAZQANAAoAKQANAAoAQQBkAGQALQBUAHkAcABlACAALQBBAHMAcwBlAG0AYgBsAHkATgBhAG0AZQAgAFMAeQBzAHQAZQBtAC4AVwBpAG4AZABvAHcAcwAuAEYAbwByAG0AcwANAAoAQQBkAGQALQBUAHkAcABlACAALQBBAHMAcwBlAG0AYgBsAHkATgBhAG0AZQAgAFMAeQBzAHQAZQBtAC4ARAByAGEAdwBpAG4AZwANAAoAJABpAG0AYQBnAGUAIAA9ACAAWwBTAHkAcwB0AGUAbQAuAEQAcgBhAHcAaQBuAGcALgBJAG0AYQBnAGUAXQA6ADoARgByAG8AbQBGAGkAbABlACgAJABpAG0AZwBmAGkAbABlACkADQAKAFsAUwB5AHMAdABlAG0ALgBXAGkAbgBkAG8AdwBzAC4ARgBvAHIAbQBzAC4AQwBsAGkAcABiAG8AYQByAGQAXQA6ADoAUwBlAHQASQBtAGEAZwBlACgAJABpAG0AYQBnAGUAKQA="
  ws:=CreateObject("Wscript.Shell")
  cmd:=[powershell.exe -noprofile -command "']+plik+['"]+"|"+ [powershell.exe  -noexit -encodedcommand ]+pscmd
  ws:run(cmd)
return

Daniele Campagna

unread,
Sep 18, 2025, 7:07:42 AM (2 days ago) Sep 18
to harbou...@googlegroups.com

RyszardR

unread,
Sep 18, 2025, 8:01:39 AM (2 days ago) Sep 18
to Harbour Users
A little bit corrected version.
Does not require powershell script on disk.


procedure image2clip(filename)

local ws,pscmd,cmd
pscmd:="cABhAHIAYQBtAA0ACgAoAA0ACgAgACAAIAAgAFsAUABhAHIAYQBtAGUAdABlAHIAKABNAGEAbgBkAGEAdABvAHIAeQApAF0ADQAKACAAIAAgACAAWwBzAHQAcgBpAG4AZwBdAA0ACgAgACAAIAAgACQAaQBtAGcAZgBpAGwAZQANAAoAKQANAAoAQQBkAGQALQBUAHkAcABlACAALQBBAHMAcwBlAG0AYgBsAHkATgBhAG0AZQAgAFMAeQBzAHQAZQBtAC4AVwBpAG4AZABvAHcAcwAuAEYAbwByAG0AcwANAAoAQQBkAGQALQBUAHkAcABlACAALQBBAHMAcwBlAG0AYgBsAHkATgBhAG0AZQAgAFMAeQBzAHQAZQBtAC4ARAByAGEAdwBpAG4AZwANAAoAJABpAG0AYQBnAGUAIAA9ACAAWwBTAHkAcwB0AGUAbQAuAEQAcgBhAHcAaQBuAGcALgBJAG0AYQBnAGUAXQA6ADoARgByAG8AbQBGAGkAbABlACgAJABpAG0AZwBmAGkAbABlACkADQAKAFsAUwB5AHMAdABlAG0ALgBXAGkAbgBkAG8AdwBzAC4ARgBvAHIAbQBzAC4AQwBsAGkAcABiAG8AYQByAGQAXQA6ADoAUwBlAHQASQBtAGEAZwBlACgAJABpAG0AYQBnAGUAKQA="
  ws:=CreateObject("Wscript.Shell")
  cmd:=[powershell.exe -noprofile -command "']+filename+['"]+"|"+ [powershell.exe  -noexit -encodedcommand ]+pscmd
  ws:run(cmd,0,.f.)
return

CV

unread,
Sep 19, 2025, 7:49:33 PM (17 hours ago) Sep 19
to Harbour Users
Hi RyszardR

Thank you for your post.
This harbour function is calling this script (the contents of pscmd var):

param
(
    [Parameter(Mandatory)]
    [string]
    $imgfile
)

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$image = [System.Drawing.Image]::FromFile($imgfile)
[System.Windows.Forms.Clipboard]::SetImage($image)

That's an equivalent of your previous post.
Many thanks! I will implement this while trying to create a .C function to do the same and not depend on external commands.

Best regards!
©

Reply all
Reply to author
Forward
0 new messages