Search code examples
c#imageclipboardbitmapsource

How to save an image to the clipboard only knowing the images path


Say if I have an image path C:\MyImages\MyImage.jpg how would I get this onto the clipboard using C#.

I know I would use the class System.Windows.Clipboard.SetImage(); but this takes a BitmapSource as the parameter. How would I get a BitmapSource object to feed into this method from the given path?


Solution

  • BitmapSource bitmapSource = new BitmapImage(new Uri("C:\\MyImages\\MyImage.jpg"));
    System.Windows.Clipboard.SetImage(bitmapSource);