?
Solved

Silver Light question -- Load images from Local Computer

Posted on 2010-04-06
3
Medium Priority
?
605 Views
Last Modified: 2013-11-26
I am trying to dynamically load images into a silverlight project.  I made a Silverlight 3 project using VS 2010 Beta.  I want to load the images on to the canvas through code.  

the function that I have is:

   private void AddImage(double Left, double Top, int Height, int Width,int imageNum)
        {
            Image myImage = new Image();
            string uriString = "../images/img." + imageNum.ToString() + ".jpg";
            BitmapImage bmp = new BitmapImage();
            Uri uri1 = new Uri (uriString,UriKind.Relative );            
            bmp.UriSource = uri1;          
 
            myImage.Source = bmp;
            myImage.Width = Width;
            myImage.Height = Height;
            myImage.SetValue(Canvas.LeftProperty, Left);
            myImage.SetValue(Canvas.TopProperty, Top);
           
            myCanvas.Children.Add(myImage);
        }

the call is a simple loop of i from 1 to 3 that calls the AddImage as follows:
AddImage(i*115,100,100,100,i);

When I made silimar code to load rectangles onto the page it worked fine, with this image function it does not seem to work.  No error messages are generated, but nothing shows up on the canvas when I run this.  
0
Comment
Question by:VoodooFrog
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 29915395
0
 

Author Comment

by:VoodooFrog
ID: 29978524
that is still not working:  here is the code as I changed it based on the code from that blog:

 private void AddImage(double Left, double Top, int Height, int Width,string path)
        {
            Image myImage = new Image();
            myImage.Source = new BitmapImage(new Uri(path, UriKind.Relative));
            myImage.Width = Width;
            myImage.Height = Height;
            myImage.SetValue(Canvas.LeftProperty, Left);
            myImage.SetValue(Canvas.TopProperty, Top);
            myCanvas.Children.Add(myImage);
}

called with
  while (i <= (Convert.ToInt16(a.Content.ToString())))
            {
                uriString = "/images/img." + i.ToString() + ".jpg";
               AddImage(((i) * 110) + 15, ((i) * 110) + 15, 100, 100,uriString);
}

in addition -- when I call    
 public MainPage()
        {            
            InitializeComponent();          
            AddImage(115,115,100,100,"/images/img1.jpg");        
        }

  it works fine apparently.  



0
 

Author Comment

by:VoodooFrog
ID: 30010745
I found a typo in my code...   a '.' after the img so the file string would  be created as img.1.jpg....   That is a frustrating mistake...  
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses
Course of the Month4 days, 14 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question