View Single Post
  #1   Spotlight this post!  
Unread 02-08-2010, 03:21 PM
PranavSathy PranavSathy is offline
Team Captain
AKA: Pranav Sathyanarayanan
FRC #0263 (Sachem Aftershock)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Holbrook, New York
Posts: 27
PranavSathy is an unknown quantity at this point
Displaying Camera Image in C# Dashboard

Dear Cheif Delphi Community,

I know this is a C++ forum, but I dont know anywhere else to post this, but either ways, I am trying to display the camera video on a custom C# form. So far, I have managed to make the the form connect to the camera on the cRIO, and understand that there is data, it even shows the maount of bytes read, ranging from 4(header and size) to 9000(I dont know), this is my current code:

Code:
if (netStream.DataAvailable)
                {
                    image.indicator.Text = "Data Available";
                    //image.videoStream.Image = Image.FromStream(netStream);
                    data = new byte[serverClient.ReceiveBufferSize];
                    
                    bytesRead = netStream.Read(data, 0, serverClient.ReceiveBufferSize);
                    //tw.WriteLine(DateTime.Now + " " + bytesRead.ToString());
                    if (bytesRead > 100)
                    {
                        try
                        {
                            MemoryStream ms = new MemoryStream(data);
                            image.videoStream.Image = Image.FromStream(ms, false, true);
                        }
                        catch (Exception ex)
                        {
                            tw.WriteLine(DateTime.Now + ex.ToString());
                        }
                    }
                }
                else if (!netStream.DataAvailable)
                {
                    image.indicator.Text = "No Data Available";
                }
Whoever knows C#, the Image.FromStream() method keeps returning a Parameter is Invalid in the excetion. Obviously I think that data(the byte[] array that stores the image data] is corrupt or something, I do not know though. Can anyone please show me some proper code here for displaying the image, btw I know the program is connected because the status label does read Data Available.
Reply With Quote