473,412 Members | 4,957 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,412 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 2600
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: 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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.