Question

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 Maps 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 following variable.

object [] GoogleMap;

After debugging I can see that in auto I am getting 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 functions 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?

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top