473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2598
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: chellappa | last post by:
Hi, This is program for socket program for server and client ... but data send from client and receive by server but i can t sen d message fro m server to client ... check i mistake .. i treed...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
1
by: Jim | last post by:
Here is a snipet of the code. // State object for receiving data from remote device. public class StateObject { // Client socket. public Socket workSocket = null; // Size of receive buffer....
2
by: Craig | last post by:
Hi I listen on a port, when data is received I raise an event (OnMessageReceived) in the while loop as follows: private void WaitForConnection() { TcpListener listener = new...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
0
by: vinothgsd | last post by:
Hi, I have created Client/Server application. In that Client side Program i have used Asynchronous Callback method for send and receive the stream. In the Receive method I want to make the...
5
by: PHS | last post by:
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...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.