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();

spImage.Children.Add(imgPicture);

}

 Thanks,

http://atomviews.com/

Advertisements

2 Comments »

  1. Now, what about actually sending an image as a byte array? It’s all well and good if you are just retrieving rote bits, but if you want to manipulate that image (since Silverlight provides no support on the client), you can’t because using System.Drawing in a WCF service is cruising for an exception, and just sending the same bytes back will throw a Catatrophic Failure exception on the client. Any advice? Can you give an example of retrieving an image in the WCF service or manipulating it?

    Comment by Daniel — September 1, 2008 @ 10:26 am | Reply

  2. Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

    Comment by sandrar — September 10, 2009 @ 3:09 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: