Sudheesh Warrier’s Weblog

August 23, 2008

Silverlight Beta 2 How to Get the Image from a Web Service and Display it in the SilverLight Content.

Filed under: Silverlight — Sudheesh Warrier @ 11:26 am
Tags: , , , , ,

Let us write the function for retriving the Image in the web service first.

 public byte[] fnGetResourceImage()


 Image imgResource =null;

string strImageFilePath;

byte [] byteImgResource;

 strImageFilePath = “MyImage.JPG”;  

FileStream fs = File.OpenRead(strImageFilePath);

 byteImgResource =newbyte[fs.Length];

fs.Read(byteImgResource, 0,Convert.ToInt32(fs.Length));


 Now this one can return the byte arry that contains the image data.

Lets move to the PAGE.XAML.CS

In your Webservice completed event handler write the below stuff:

 Static void GetResourceImageService_fnGetResourceImageCompleted(object sender, fnGetResourceImageCompletedEventArgs e)


 Byte[] bImage = e.Result;

 System.Windows.Media.Imaging.BitmapImage bmpImage =new System.Windows.Media.Imaging.BitmapImage();

bmpImage.SetSource(newMemoryStream(bImage,false ));

Image imgPicture =new Image();

imgPicture.Source = bmpImage;

StackPanel spImage =new StackPanel();




Blog at