Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Vista C# Windows
I have a client/server setup that when the client sends the message of screen/ the server takes a screenshot, converts it to a byte[] (array) and sends it to my client. Upon recieving the byte array the client converts it to a stream and back to an image file using Image.FromStream and displays it in a picturebox. When testing this the picturebox shows about and inch of the top of the picture while everything under it becomes a dark grey and then it gives me an error saying "Parameter is not valid". I would like for the picture box to show the entire image. My code is below.
public void UpdateArray(byte[] array)  // update array of bytes
{
    MemoryStream ms = new MemoryStream(array);
    Image returnImage = Image.FromStream(ms);  // <-- Parameter Error comes from here.
    pictureBox1.Image = returnImage;
}
Thank you Smile | :)
Posted 15-Feb-10 4:43am
Edited 15-Feb-10 5:11am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Nevermind I figured it out. The file was too big I guess, instead I split it into several chunks and sent them individualy.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The problem is with the data you load into the byte array. Show what you load into that and I'm sure we can help you. It should be the image data as it would be saved to a file (so, includes header information and such).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thanks for the reply. The code I used to load the image into a byte array on the server side is shown below.
if (str == "screen/")
                {
                    int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
                    int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
                    Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
                    Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
                    gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
                    {
                        try
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                bmpScreenShot.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                byte[] array = ms.ToArray();
                                server.Send(array);
                            }
                        }
If I use those same code snippets all in a single windows form without sending through a socket and to a client it works fine. So im assuming it has something to do with the transfer between server to client. Help is greatly appriciated. Thank you.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Sounds like the problem is with your network code. More than likely, you are not getting all of the data during the transfer. This is pretty common. This would make it so only part of your image gets displayed, because only part of the data made it across the wire. Check the length of the array and that should confirm this (the array will be shorter than you expect).
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 589
1 OriginalGriff 379
2 CPallini 205
3 RyanDev 175
4 Sergey Alexandrovich Kryukov 160
0 OriginalGriff 5,689
1 Sergey Alexandrovich Kryukov 4,783
2 Peter Leow 2,954
3 Maciej Los 2,819
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 15 Feb 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid