1

I have this small utility, called PureRef, it lets me import multiple images and view them as if they were one large image.

In File Explorer, I can right a click a selection consisting of multiple images, copy it and then in PureRef Right Click > Paste. This will paste all of the images found in the Clipboard.

Here is recording showing what I mean

I essentially want to write a function that will let me do Step 1 in PowerShell:

  1. Copy the image items with something like $MyPaths | Set-Clipboard
  2. Switch to the PureRef window
  3. Paste

Step 2 and 3 are not meant to be done in PowerShell.

I am stuck on implementing Step 1 in PowerShell though, if I have a variable like so:

 $MyPaths
    Directory: C:\Temp
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          24/03/2021    19:39         146775 pinterest_490822059382335736.jpg
-a---          24/03/2021    19:39         114598 pinterest_490822059380529968.jpg
-a---          24/03/2021    19:39         102667 pinterest_490822059380520311.jpg

Then execute $MyPaths | Set-Clipboard before switching to the PureRef window and invoking paste (Ctrl+ V or Right click > Paste) will not work. Oddly enough the following works:

$MyPaths[0] | Set-Clipboard

I can paste that single image into PureRef, I don't know if this is PowerShell's doing or not. As soon as I attempt to paste more than one image I am back to square one.

In the example of Explorer that I shared. I think Explorer is copying the actual image pixel data.

Is it possible to also do this in PowerShell? Instead of placing paths in the clipboard, place the pixel data there. Or maybe simulate what explorer is doing via a Shell object?

I tried searching and experimenting, the closest I came to a solution is by THIS answer by Ansgar Wiechers, which partly works after I modify it:

Add-Type -Assembly System.Windows.Forms
Add-Type -Assembly System.Drawing

$img = [Drawing.Image]::FromFile($path[1])
[Windows.Forms.Clipboard]::SetImage($img)

But notice the ...FromFile($path[1]), This solution also only works with a single file.

I really need to pass multiple files from various directories, as I want to take advantage of the complex searching/Selection operations I can perform in PowerShell.

  • It appears that you will need to determine the layout and sizes of the images. https://www.reddit.com/r/PowerShell/comments/f4k8m7/is_it_possible_to_merge_two_images/ might be of interest. – lit Jun 19 '23 at 17:01
  • @lit , hey I went through the post you linked to, Its seems the OP is looking to merge the images. The solutions offered there are also about merging images via Magick or encoding via Base64. I am not looking to do anythings like that. I am looking to import the images as individual objects in to the PureRef program. – Ralf_Reddings Jun 19 '23 at 17:56

1 Answers1

4

To emulate copying multiple files in Explorer, use [Clipboard]::SetFileDropList():

[System.Windows.Forms.Clipboard]::SetFileDropList($MyPaths.FullName)
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Brilliant, that did it and its fast too! So this is how explorer is achieving it. You link offers allot of reading material. Thanks allot – Ralf_Reddings Jun 19 '23 at 19:13