Image source UriKind problem

Page 1 of 1

1 Replies - 2775 Views - Last Post: 18 May 2012 - 09:35 AM Rate Topic: -----

#1 morsev  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 26-September 10

Image source UriKind problem

Posted 18 May 2012 - 07:21 AM

Hi
i have a project it's name is 'xx'.
i create a folder "images" that have this path :
xx\bin\Debug\images\

images contain only one photo it's name is "1.jpg"
the MainWindow contain Image control
i set this code to load the image source but it doesn't work why ??:
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Image i = sender as Image; ;
            BitmapImage b = new BitmapImage(new Uri(@"images\1.jpg",UriKind.Relative));
            i.Source=b;
            
        }



How can I load the Image source by code ??
Thanks in advance :)

Is This A Good Question/Topic? 0
  • +

Replies To: Image source UriKind problem

#2 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 271
  • View blog
  • Posts: 550
  • Joined: 07-July 10

Re: Image source UriKind problem

Posted 18 May 2012 - 09:35 AM

Don't try to be proficient and use little code. Be very verbose with your code and debug. Once you are sure you are getting the results you want you can refactor the code to be shorter. Any of the little bits could be causing your problem.

private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
   LoadImage(sender as Image);
}

private void LoadImage(Image image)
{
   if (image == null)
      return;

   Uri uri = new Uri(@"images\1.jpg", UriKind.Relative);
   BitmapImage bitmapImage = new BitmapImage(uri);
   image.Source = bitmapImage;
}

Put a breakpoint on the first line of LoadImage and step over each line. Check every variable when it is made. Hover your mouse over "uri" after passing that line. Does the path look correct? Does the bitmap build correctly? Maybe the problem is casing the sender as an Image?

Also, you never gave us the exact error you are receiving.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1