Stream Object

  • Thread starter Thread starter Guest
  • Start date Start date
Jason said:
How can I create a stream object from webservice that returns an image
in byte format?

Well, what have you currently got from the webservice? If you've got a
byte array, I suggest you have a look at MemoryStream.
 
Hello,

Thanks for your post. I believe the following code snippet is helpful:

//----------------Image to byte[] and byte[] to Image code------------------
public static byte[] ToByteArray(Image image)
{
// create a memory stream
MemoryStream stream = new MemoryStream();
// save the image into the memory stream
image.Save(stream, ImageFormat.Jpeg);
// return the stream buffer
return stream.GetBuffer();
}

public static Image ToImage(byte[] buffer)
{
// load the buffer into a memory stream
MemoryStream stream = new MemoryStream(buffer);
// load the image from the stream and return it
return new Bitmap(stream);
}
//--------------------end of-----------------------

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I got it to work!!!

Here's the code:

Dim ByteStream = New MemoryStream(Dilbert.DailyDilbertImage)

With picViewer
.Image = Image.FromStream(ByteStream)
.BringToFront()
End With

Jason Carter
 
Back
Top