Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Loading image at run time

Loading image at run time

Scheduled Pinned Locked Moved WPF
helpcsharpwpflearning
4 Posts 2 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yoyosch
    wrote on last edited by
    #1

    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

    L Y 2 Replies Last reply
    0
    • Y Yoyosch

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 Articles

      Just a grain of sand on the worlds beaches.

      Y 1 Reply Last reply
      0
      • Y Yoyosch

        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

        Y Offline
        Y Offline
        Yoyosch
        wrote on last edited by
        #3

        I found it out :) : bi3.UriSource = new Uri("smiley_stackpanel.PNG", UriKind.Relative);

        1 Reply Last reply
        0
        • L Lost User

          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 Articles

          Just a grain of sand on the worlds beaches.

          Y Offline
          Y Offline
          Yoyosch
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups