1

I would like to add the image directly to the image box, so imgVarschaubild.Source = sa;

Unfortunately this does not work, how do I do it? Without which I have to save the picture first but must directly insert the picture?

My solution at the moment:

System.Drawing.Image sa;


    ....


if (saveFileDialog.ShowDialog() == true)
{
  sa.Save(saveFileDialog.FileName);
  MessageBox.Show(saveFileDialog.FileName);
  ImageSource imageSource = new BitmapImage(new Uri(saveFileDialog.FileName));

  imgVorschaubild.Source = imageSource;
}
imsome1
  • 1,182
  • 4
  • 22
  • 37
  • System.Drawing.Image is a Windows Form class. What image do you want to display? Is it an image file or what? – mm8 Mar 08 '17 at 11:04
  • The image was made by an OxyPlot, so I have the image only as a variable and would like to add it directly to the image box. I do not want to save it before. (I have created the image in a method and this method returns me the image.) –  Mar 08 '17 at 11:06

2 Answers2

0

It seem's like you are not using the MVVM pattern. I hardly recommend it. If you use it you could easily bind your imagePath to an Image.

You just need a string property in your ViewModel and bind to it in your View like

<Image Source="{Binding ImagePath}" />
Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51
0

System.Drawing.Image is a Windows Form class. You could try to convert it to a BitmapSource using any of the suggestions and code samples from here:

Show Drawing.Image in WPF

Once you have done that you could set the Source property of the Image element to the BitmapSource:

imgVorschaubild.Source = GetImageStream(sa);
Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thank you for your answer! I tried different things, but without success. Would you give me a clue? –  Mar 08 '17 at 11:28
  • "different things"? Did you try the GetImageStream as I suggested? What happened? – mm8 Mar 08 '17 at 11:29
  • When I use `GetImageStream` comes as a message _The name does not exist in the current context_. –  Mar 08 '17 at 12:09
  • You need to copy the GetImageStream method from the link I gave you into your code...It is not a built-in method. – mm8 Mar 08 '17 at 12:17
  • Sorry Sir, Thank you for your sincere effort. –  Mar 08 '17 at 12:20