Click here to Skip to main content
13,000,002 members (49,250 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everyone.....

i got a situation... in my project, i need to show images from database on silver light pages...

so i developed like this...

in my XAML...
<Image Grid.Row="2" Margin="10" x:Name="image" Width="300" Height="200" HorizontalAlignment="Left"></Image>

and in my code
byte[] imageData = questions.ElementAt(Convert.ToInt16(x.Name)).Image;
            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(new MemoryStream(imageData));
            image.Source = bitmapImage;

but the image is not rendering.... can anyone help me
Posted 12-Feb-13 19:05pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi.If i was you:
Save the name of my images in DataBase and Create a method like this:
public static BitmapImage GetBitMapImage(string relativeImage)
string imagePath=string.format("pack://application:,,,/{0};component/Images/{1}",Assembly.GetExecutingAssembly().GetName().Name,relativeImage);

URI uri=new URI(imagePath,UriKind.RelativeOrAbsolute);
return new BitmapImage(uri);

"Images" in imagePath is a folder in your application that all of image is located in it.

when you need to an must write:
Image myImage=new Image();
myImage.Source=GetBitMapImage(this place must populate with your image name that is saved in DataBase);

for example :

this acction is useful because when you need your image is loaded.
Good Luck
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100