Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Setting Image Source Dynamically
6 replies. Latest Post by Sopheap Ly on April 1, 2008.
(0)
krishnak...
Member
33 points
37 Posts
04-01-2008 7:06 AM |
I need to assign sources to the Images Dynamically at runtime.I get the Image sources by calling web service which returns me a array of strings which contains the sources.How could i do that.
Regards,
Krishna kiran
pefc
100 points
49 Posts
04-01-2008 7:11 AM |
Try this: YourImage.Source = new BitmapImage(new Uri(yourstring, UriKind.Relative));
Try this:
YourImage.Source = new
04-01-2008 7:33 AM |
Can i Give Local path of the local file to the image in a string format as a source to the Image.
such as @"C:\Documents and Settings\example.jpg" at run time
04-01-2008 7:34 AM |
Can i give Local file path to a Image such as @"C:\Documents and Settings\" in the source string
robhouwe...
Contributor
3158 points
540 Posts
04-01-2008 7:57 AM |
No, Silverlight runs in the browser, so c:\ is c:\ on the PC of the user viewing your site, not on your server.
(If this has answered your question, please click on mark as answer on this post)Cheers!Rob Houweling
gongdo
98 points
04-01-2008 8:44 AM |
You can't access local resources cuz security issues.But, you can recieve local files from user by OpenFileDialog.
here is some sample codes that load image from local by using OpenFileDialog.Copy this code to Page UserControl and try it :)
public Page() { InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded); }
void Page_Loaded(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "All Images|*.jpg;*.png|JPEG Images(*.jpg)|*.jpg|PNG Images(*.png)|*.png"; ofd.EnableMultipleSelection = false; DialogResult result = ofd.ShowDialog(); if (result == DialogResult.OK) { FileDialogFileInfo file = ofd.SelectedFile; BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(file.OpenRead()); // <-- load bitmap image as stream.
Image img = new Image(); img.Source = bitmap; img.Stretch = Stretch.None; LayoutRoot.Children.Add(img); } }
Hope it helps.--Gongdo
Sopheap Ly
Participant
902 points
205 Posts
04-01-2008 9:05 AM |
Is someone trying to create a virus here? :D