473,379 Members | 1,253 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,379 software developers and data experts.

Form an image from received bytes from server and display that image into the picturebox

Hello,

I am writing 1 client-server application in which I have written my
server in C on linux system and client in C#.

My server is sending image bytes of that image size to the client.
After receiving image bytes on client side, I want to form an image
from received bytes and want to display that image onto the picture-box
control.

Server Code:
-------------------
FILE *fp;
char buf[1024];
fp = fopen("./line.jpg","rb");

if(!stat(fileName,&file))
printf("File Size : %d\n",file.st_size);

while(!feof(fp))
{
bytesRead = fread(buf, 1, file.st_size, fp);

sent = sendto(sock, buf, bytesRead, 0,
(struct sockaddr *)&from, fromlen);

}

Client code:
-----------------
Socket sockVar;
byte[] tmpBuf = new byte[size];
MemoryStream streamImage = null;

recv = sockVar.ReceiveFrom(tmpBuf, 0, size, SocketFlags.None,
RemoteEndPoint);

streamImage = new MemoryStream(tmpBuf, true);
streamImage.Write(tmpBuf, 0, tmpBuf.Length);

try
{
picImageBox.Image = Image.FromStream(streamImage);
streamImage.Flush();
streamImage.Close();
}
catch (Exception excp)
{
MessageBox.Show(excp.Message);
}

-----------------------------------------------------------------------------------------------------------------------------
In above code, client-server communication is properly happening and i
m able to receive all the bytes of the image into the corresponding
buffer. I m not getting any error, exception but the expected image is
not getting displayed into the picture-box. Is there any other way to
display an image?

Thanks in Advance.

Regards,
Nishi

Jul 25 '06 #1
2 2331
Try Invalidating the picturebox (forces it to redraw)

Jul 25 '06 #2
<ni*********@gmail.comwrote:
I am writing 1 client-server application in which I have written my
server in C on linux system and client in C#.

My server is sending image bytes of that image size to the client.
After receiving image bytes on client side, I want to form an image
from received bytes and want to display that image onto the picture-box
control.
<snip>
Client code:
-----------------
Socket sockVar;
byte[] tmpBuf = new byte[size];
MemoryStream streamImage = null;

recv = sockVar.ReceiveFrom(tmpBuf, 0, size, SocketFlags.None,
RemoteEndPoint);
You need to make sure you've read the whole thing - you're unlikely to
get it from one call.
streamImage = new MemoryStream(tmpBuf, true);
streamImage.Write(tmpBuf, 0, tmpBuf.Length);
When you've written this, you should rewind the stream - set the
Position to 0.
try
{
picImageBox.Image = Image.FromStream(streamImage);
streamImage.Flush();
streamImage.Close();
}
catch (Exception excp)
{
MessageBox.Show(excp.Message);
}
When you've used Image.FromStream, you shouldn't close the stream
afterwards - the image will do that when it is disposed.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dev | last post by:
Dear Friends, I am passing the image name, size (in bytes) and imgaeformat (like jpg or bmp or pdf) through the network. I want display the image into picturebox without saving image...
6
by: Dean Slindee | last post by:
Does anybody have an actual example of retrieving an Image data type column from a SQL Server table using a dataset (not a datareader)? I would like to see the statements that would move the...
6
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the...
1
by: | last post by:
How do I control the layering of 4 forms of identical size and position to cause the desired form to be second from the top.. Form1 has my welcome screen etc.and the code for file manipulations...
4
by: rodchar | last post by:
hey all, i have an image that i want to put on my form and was just wondering if there is a way to take away the white background on the image (make it transparent)? thanks, rodchar
7
by: kebalex | last post by:
Hi, I have an app (written in .NET 2.0) which updates a picturebox according to some user input (a slider control). when the user makes a change i loop through all of the pixels, do a...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
1
by: starter08 | last post by:
Hi, I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket. On the server side I have a cgi...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.