Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...
XML
<Image Grid.Row="2" Margin="10" x:Name="image" Width="300" Height="200" HorizontalAlignment="Left"></Image>


and in my code
C#
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

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 image.you must write:
Image myImage=new Image();
myImage.Source=GetBitMapImage(this place must populate with your image name that is saved in DataBase);

for example :
myImage.source=GetBitMapImage("SaveIcon.png");


this acction is useful because when you need your image is loaded.
Good Luck
 
Share this answer
 
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900