Error when using Invoke Method activity to SetImage to clipboard

Hi guys, i’m trying to set a screenshot to the clipboard so that i can do ctrl+v and paste the image in a word document later on. However, in the Invoke Method activity, it keeps on having an issue when i do “SetImage” to the clipboard.

I have referred to this thread but i still don’t understand what it means. This is also the workflow that i am trying to work on: Clipboard.xaml (8.8 KB)

Just to clarify, the problem i am having is with my company work machine, so i cannot take screenshot from it. However, the workflow is the same as the one i provided above. I am just unclear as to why it is not working.

If you get the same error as the thread you linked to, have you tested with System.Windows.Clipboard (without Forms) as target type instead?

Provides static methods that facilitate transferring data to and from the system Clipboard.

Hi thanks for the reply. I’ve just tried it without the .forms as you said but it still says that there is no public static method named “SetImage”

Have you updated the parameter also? SetImage only accept image as BitmapSource (System.Windows.Media.Imaging.BitmapSource).

but the image i am trying to load into the clipboard is of variable type “image” though. Since what i am trying to do is take a screenshot and after that, save/load it into the clipboard so that i can Ctrl+V later on. The take screenshot activity only supports image variables as it outputs to my understanding

Then you need to convert it to BitmapSource first. My recommendation is to use Invoke Code instead of Invoke Method using the following code:

Dim bi As System.Windows.Media.Imaging.BitmapImage = New System.Windows.Media.Imaging.BitmapImage

bi.BeginInit()
bi.StreamSource = New System.IO.MemoryStream(in_Screenshot.ByteArray)
bi.EndInit()

System.Windows.Clipboard.SetImage(bi)

Thank You So Much!!! It works fine now. Could you explain to me what is the difference between invoke method and invoke code?

You are welcome! Good to hear that it’s working. With Invoke Method you can only call one method (per activity). With Invoke Code you can call how many methods you want and write other code. Invoke Method can access your workflow variables directly while Invoke Code only can access them via arguments.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.