Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Silverlight
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
good
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 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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 231
3 Sergey Alexandrovich Kryukov 211
4 kbrandwijk 204
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 405
4 thatraja 370


Advertise | Privacy | Mobile
Web03 | 2.8.140902.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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