469,600 Members | 2,278 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

How to convert a socket data buffer into pictures.

PHS
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?
Jul 21 '05 #1
5 2441
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" <PH*@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
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?

Jul 21 '05 #2
This is the correct way.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ub*************@TK2MSFTNGP12.phx.gbl...
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" <PH*@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
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?


Jul 21 '05 #3
PHS
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" wrote:
This is the correct way.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ub*************@TK2MSFTNGP12.phx.gbl...
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" <PH*@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
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?



Jul 21 '05 #4
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" schrieb:
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" wrote:
This is the correct way.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ub*************@TK2MSFTNGP12.phx.gbl...
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" <PH*@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
>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?


Jul 21 '05 #5
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" schrieb:
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" wrote:
This is the correct way.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ub*************@TK2MSFTNGP12.phx.gbl...
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" <PH*@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
>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?


Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by chellappa | last post: by
reply views Thread by Macca | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.