views:

330

answers:

1

I am developing smart device application in C#. In that I am calling the web services. The web service method return google map. The return type of the method is object []. The object [] contains the image in byte format. The soap response for google map image is xsi:type="xs:base64Binary". In object I am not getting the string. In object I am getting the byte array. So I am catching the response of web service in followig variable.

object [] GoogleMap;

After dubugging I can see that in auto I am gettng the result as follows.

Name: Value: GoogleMap {object[1]} [0] {byte[23570]}

I need to display the actual image in my application. What type of casting I need to do to display the image.Please make sure that all the core fuctions of .net framework does not work with .net compact framework. Can you provide me the code or any link through which I can resolve the above issue?

A: 

First you need to get the byte array out:

byte[] data = (byte[]) objects[0];

Then create a MemoryStream around it:

MemoryStream stream = new MemoryStream(data);

Now create a Bitmap from the stream:

Bitmap bitmap = new Bitmap(stream);

Note that you should not close the MemoryStream - when you dispose of the Image, that will close the stream.

(EDIT: Changed from Image.FromStream to calling the Bitmap constructor as Image.FromStream appears not to be in the CF.)

Jon Skeet