Loading image at run time
-
My problem is very simple: I have one project in my solution. It contains WPF User Control and WPF Window (which displays this control). In User Control I have an Image control:
<Image Margin="56,22,44,128" Name="image1" Stretch="Fill" Source="/WpfApplication20;component/Niebieskie góry.jpg" />
In .cs file I got the following:public UserControl1() { InitializeComponent(); image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg")); }
Both images are included into my project as a RESOURCE. Project builds with no errors. However, it throws exception at run time. In my view the reason is that it can`t find the image to replace the previous one. Thank you very much for any help -
My problem is very simple: I have one project in my solution. It contains WPF User Control and WPF Window (which displays this control). In User Control I have an Image control:
<Image Margin="56,22,44,128" Name="image1" Stretch="Fill" Source="/WpfApplication20;component/Niebieskie góry.jpg" />
In .cs file I got the following:public UserControl1() { InitializeComponent(); image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg")); }
Both images are included into my project as a RESOURCE. Project builds with no errors. However, it throws exception at run time. In my view the reason is that it can`t find the image to replace the previous one. Thank you very much for any helpYoyosch wrote:
image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg"));
Please change this line of code to this and give it a go.
image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg", UriKind.Relative));
If you still get an exception, please post the exception. Also, where in your solution are the images? From the above, I assume that they are in the root folder of the application and not in a subfolder, correct?Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
-
My problem is very simple: I have one project in my solution. It contains WPF User Control and WPF Window (which displays this control). In User Control I have an Image control:
<Image Margin="56,22,44,128" Name="image1" Stretch="Fill" Source="/WpfApplication20;component/Niebieskie góry.jpg" />
In .cs file I got the following:public UserControl1() { InitializeComponent(); image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg")); }
Both images are included into my project as a RESOURCE. Project builds with no errors. However, it throws exception at run time. In my view the reason is that it can`t find the image to replace the previous one. Thank you very much for any help -
Yoyosch wrote:
image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg"));
Please change this line of code to this and give it a go.
image1.Source = new BitmapImage(new Uri(@"Zachód slonca.jpg", UriKind.Relative));
If you still get an exception, please post the exception. Also, where in your solution are the images? From the above, I assume that they are in the root folder of the application and not in a subfolder, correct?Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
Our solution seems to work on simple Images. It does not, however, on 3D graphics. I attempt to create a ImageBrush (for a material on 3D figure). I got image file "FieldExample.png" which is in the root directiory (the same as *.csproj). It is included into project. Build action is set to Resource. I tried the following code:
DiffuseMaterial material = new DiffuseMaterial(); ImageBrush brush = new ImageBrush(); brush.ImageSource = new BitmapImage(new Uri("FieldExample.png", UriKind.Relative)); material.Brush = brush;
However, I`m getting run time XamlParseException. Besides, Watch set on brush.ImageSource.Height property says: System.IO.FileNotFoundException. Please don`t hesitate to ask me for a draft solution with that problem if needed Thank you very much for any help