How to convert a socket data buffer into pictures.

G

Guest

I have a c# client application that connects to a network socket. When
connected, the listener sends a network stream containing bitmap, jpeg, data
from a file nominated by the client. The client application (also c#)
receives the data into a byte[] array. I want to pass the byte[] array
directly to a picture control on the form. I can't find a way to do this so I
used a file stream and write the byte[] array to a file, and then pass that
pathname into the Image.LoadFile(pathname) method and then assign the image
to the picture, as in Picture.Image = RuntimeImage.

This works but having to use an interface file to get the data into the
picture control is not ideal. Is it possible somehow to massage the byte[]
array I got from the NetworkStream directly to the Picture control?
 
C

Chris, Master of All Things Insignificant

I haven't tested this and not positive that it would work, but can't you use
the share function Image.FromStream(Stream) as Image. Just pass in your
stream.

Chris
 
L

Landley

This is the correct way.


Chris said:
I haven't tested this and not positive that it would work, but can't you use
the share function Image.FromStream(Stream) as Image. Just pass in your
stream.

Chris


PHS said:
I have a c# client application that connects to a network socket. When
connected, the listener sends a network stream containing bitmap, jpeg,
data
from a file nominated by the client. The client application (also c#)
receives the data into a byte[] array. I want to pass the byte[] array
directly to a picture control on the form. I can't find a way to do this
so I
used a file stream and write the byte[] array to a file, and then pass
that
pathname into the Image.LoadFile(pathname) method and then assign the
image
to the picture, as in Picture.Image = RuntimeImage.

This works but having to use an interface file to get the data into the
picture control is not ideal. Is it possible somehow to massage the byte[]
array I got from the NetworkStream directly to the Picture control?
 
G

Guest

Thanks guys.

I tried that and ended up with this chunk of code:

TcpClient S = new TcpClient("localhost", 50001);
NetworkStream NS = S.GetStream();
Picture.Image = Image.FromStream(NS);
Picture.Refresh();
NS.Close();
S.Close();

It works 100% fine. I could receive image files (bmp/jpg) in size from 4k
upto 1.6Mb and they displayed perfectly.

Peter.


Landley said:
This is the correct way.


Chris said:
I haven't tested this and not positive that it would work, but can't you use
the share function Image.FromStream(Stream) as Image. Just pass in your
stream.

Chris


PHS said:
I have a c# client application that connects to a network socket. When
connected, the listener sends a network stream containing bitmap, jpeg,
data
from a file nominated by the client. The client application (also c#)
receives the data into a byte[] array. I want to pass the byte[] array
directly to a picture control on the form. I can't find a way to do this
so I
used a file stream and write the byte[] array to a file, and then pass
that
pathname into the Image.LoadFile(pathname) method and then assign the
image
to the picture, as in Picture.Image = RuntimeImage.

This works but having to use an interface file to get the data into the
picture control is not ideal. Is it possible somehow to massage the byte[]
array I got from the NetworkStream directly to the Picture control?
 
G

Guest

Hello,

First, sorry for my English.

I have the same problem, with the NET CompactFramework. With
NETCF the Image.FromFile method is not available.
Have you other solutions for these problem?

Thank you

PHS said:
Thanks guys.

I tried that and ended up with this chunk of code:

TcpClient S = new TcpClient("localhost", 50001);
NetworkStream NS = S.GetStream();
Picture.Image = Image.FromStream(NS);
Picture.Refresh();
NS.Close();
S.Close();

It works 100% fine. I could receive image files (bmp/jpg) in size from 4k
upto 1.6Mb and they displayed perfectly.

Peter.


Landley said:
This is the correct way.


Chris said:
I haven't tested this and not positive that it would work, but can't you use
the share function Image.FromStream(Stream) as Image. Just pass in your
stream.

Chris


I have a c# client application that connects to a network socket. When
connected, the listener sends a network stream containing bitmap, jpeg,
data
from a file nominated by the client. The client application (also c#)
receives the data into a byte[] array. I want to pass the byte[] array
directly to a picture control on the form. I can't find a way to do this
so I
used a file stream and write the byte[] array to a file, and then pass
that
pathname into the Image.LoadFile(pathname) method and then assign the
image
to the picture, as in Picture.Image = RuntimeImage.

This works but having to use an interface file to get the data into the
picture control is not ideal. Is it possible somehow to massage the byte[]
array I got from the NetworkStream directly to the Picture control?
 
G

Guest

Hello,

First, sorry for my English.

I have the same problem, with the NET CompactFramework. With
NETCF the Image.FromFile method is not available.
Have you other solutions for these problem?

Thank you

PHS said:
Thanks guys.

I tried that and ended up with this chunk of code:

TcpClient S = new TcpClient("localhost", 50001);
NetworkStream NS = S.GetStream();
Picture.Image = Image.FromStream(NS);
Picture.Refresh();
NS.Close();
S.Close();

It works 100% fine. I could receive image files (bmp/jpg) in size from 4k
upto 1.6Mb and they displayed perfectly.

Peter.


Landley said:
This is the correct way.


Chris said:
I haven't tested this and not positive that it would work, but can't you use
the share function Image.FromStream(Stream) as Image. Just pass in your
stream.

Chris


I have a c# client application that connects to a network socket. When
connected, the listener sends a network stream containing bitmap, jpeg,
data
from a file nominated by the client. The client application (also c#)
receives the data into a byte[] array. I want to pass the byte[] array
directly to a picture control on the form. I can't find a way to do this
so I
used a file stream and write the byte[] array to a file, and then pass
that
pathname into the Image.LoadFile(pathname) method and then assign the
image
to the picture, as in Picture.Image = RuntimeImage.

This works but having to use an interface file to get the data into the
picture control is not ideal. Is it possible somehow to massage the byte[]
array I got from the NetworkStream directly to the Picture control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top