Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
put multiple image files to the clipboard
#1
The following code can put a single image(A.png) to the clipboard,

but is it possible to put multiple images(A.png; B.png; C.png) at once?

I now understand that simulating manual operations is achievable:
1. Select three images: A.png, B.png, and C.png.
2. Press Ctrl+C.
3. Act elm.
4. Press Ctrl+V.
 
Code:
Copy      Help
var img = Image.FromFile(folders.Desktop+"A.png");
var dimg = new clipboardData().AddImage(img);

//act elm

clipboard.pasteData(dimg);
#2
Quote:Select three images

Select 3 files in File Explorer?

Exists standard file formats to store multiple file paths in the clipboard, but not to store multiple image data. If the target program uses its own format, you need to know it and create data in that format.
#3
Quote:Select 3 files in File Explorer?
Yes

I want to send multiple pictures using the clipboard because sometimes I want to execute this operation asynchronously. If I use simulated execution, the operations in two threads will conflict.
Additionally, I would like to know how to avoid such conflicts? For example, when multiple mouse operations are happening simultaneously, how can one operation be prioritized to complete first?
#4
Code:
Copy      Help
var dimg = new clipboardData().AddFiles(path1, path2, path3);
dimg.SetClipboard();
 


To avoid conflicts when using multiple threads, I usually use the C# lock keyword. Don't know how to prioritize.
#5
Useful, thank you.

The prioritization handling is interesting; Wink

it can successfully execute as long as the mouse or keyboard are not being used simultaneously. I'm currently unable to find a solution.
#6
The `GetFiles` function in Code1 does not support regular expressions. Therefore, in Code2, I used the `enumFiles` function from LA, which seems a bit complex. It would be very convenient to have an extension method for `GetFiles` that supports regular expressions.

Code1:
Code:
Copy      Help
var ar1 = Directory.GetFiles(dirPath, "AZ?.jpeg"); //files as string[]
print.it(ar1);
var dimg = new clipboardData().AddFiles(ar1);

Code2:
Code:
Copy      Help
var a = filesystem.enumFiles(dirPath, "**m AZ?.jpeg||SX?.jpeg").ToArray();
List<string> paths = new List<string>();
foreach (var f in a) {
    var path = f.FullPath;
    print.it(path);
}
string[] ar1 = paths.ToArray();
var dimg = new clipboardData().AddFiles(ar1);
#7
In tool Get files in folder check Select path.
#8
Thank you, the generated code is excellent.
Code:
Copy      Help
var ar1 = filesystem.enumFiles(dirPath, "**m AZ?.jpeg||SX?.jpeg")
    .Select(o => o.FullPath)
    .ToArray();


Forum Jump:


Users browsing this thread: 1 Guest(s)