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

Imaging problem

8
I m developing a remote surveillance system in C# which takes screenshots at 3 seconds and sends the image to the remote server.

The problem is after 7 to 8 screenshots(sometimes on the very first), I get an exception at the server of
Invalid parameter to MemoryStream

I m loading the byte buffer into the memory stream obj.

Thnx in advance 4 any help.
Feb 3 '07 #1
5 964
kenobewan
4,871 Expert 4TB
Are you closing the stream each time and disposing of the image?
Feb 3 '07 #2
Motoma
3,237 Expert 2GB
I m developing a remote surveillance system in C# which takes screenshots at 3 seconds and sends the image to the remote server.

The problem is after 7 to 8 screenshots(sometimes on the very first), I get an exception at the server of
Invalid parameter to MemoryStream

I m loading the byte buffer into the memory stream obj.

Thnx in advance 4 any help.
Welcome to The Scripts.
When the error occurs, what method are you calling? What are the objects you are passing to the MemoryStream object? Could we see the code where the error is occuring?
Feb 4 '07 #3
akshah
8
Welcome to The Scripts.
When the error occurs, what method are you calling? What are the objects you are passing to the MemoryStream object? Could we see the code where the error is occuring?
Sending Code -- At client side
public void Send()
{
Image img = Image.FromFile(@"C:\image.jpg");
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Jpeg);
byte[] buf2 = ms.GetBuffer();

byte[] buf = new byte[(buf2.Length/2) + 1];
for (int i = 0; i < buf2.Length; i++)
{
if (i % 2 == 0)
{
buf[i / 2] = buf2[i];
}
}

udpClient.Send(buf, buf.Length,"localhost",8001);
ms.Close();
img.Dispose();
}

************************************************** ***********************
//Receiving Code -- At the server side
public void Receive()
{
UdpClient udpClient = new UdpClient(8001);
while (true)
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8001);

byte[] buf2 = udpClient.Receive(ref endPoint);

byte[] buf = new byte[buf2.Length * 2];
for (int i = 0; i < buf.Length; i+=2)
{
buf[i] = buf2[i/2];
buf[i+1]=buf2[i/2];
}
//The ERROR occurs in the following line: Invalid parameter
MemoryStream ms = new MemoryStream(buf);
Image img = Image.FromStream(ms);
Invoke(new UpdatePicBoxDelegate(UpdatePicBox), new object[] { img });

ms.Close();
}
}
Feb 5 '07 #4
kenobewan
4,871 Expert 4TB
Obviously, buf is the invalid parameter. I suggest writing buf value to see if it is valid. Then work backwards through a debugging procedure until the code works...

Hope that this helps.
Feb 5 '07 #5
Motoma
3,237 Expert 2GB
Obviously, buf is the invalid parameter. I suggest writing buf value to see if it is valid. Then work backwards through a debugging procedure until the code works...

Hope that this helps.
I concur.
Perhaps enclose it in a try...catch section, and report the typeof buf as well as the values when it fails.
Feb 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark Nelson | last post by:
Hi I'm trying to build Imaging 1.1.4 in Solaris 9, I get passwd the first step i.e the building of libImging. However when I execute a python setup.py build I get the following error - gcc...
1
by: mark | last post by:
I feel fairly well versed in getting Tkinter to do what I want, but now I'm venturing into the whole imaging thing, and placing text and graphics over some static background image. I'm trying to...
2
by: Richard | last post by:
In the days of VB6 I would often use the Wang/Kodak Imaging control that ships with Windows to process TIFF files. Drop the ocx on a form and TIFF file manipulation is all very easy. So how do...
0
by: MC | last post by:
Hi, I'm developing an VB.NET app that converts TIFFs to PDFs using Office Imaging 2003 and Adobe Distiller 6.0 in the follwing way: 1. Using automation, I open the TIFF file with Office...
0
by: Stedak | last post by:
My application seems to freeze when Microsoft Office Document Imaging is set as the default for loading images. If the Windows Picture and Fax Viewer is used there is no problem. When I set a break...
3
by: David A. Osborn | last post by:
I currently have a class that has an enumeration of graphics extensions that it supports ie: Public Enum GraphicFormats JPG JPEG BMP TIFF End Enum
2
by: moishyyehuda | last post by:
can I download Python Imaging Library (PIL) for linux.
5
by: Prateek | last post by:
Hi. I'm creating a web-application using CherryPy 2.2.1. My application needs to process images (JPG/PNG files) to 1) create thumbnails (resize them) 2) overlay them on a custom background (a...
0
by: tavares | last post by:
----------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) International Journal of...
10
by: Nathan Sokalski | last post by:
How do I create a new System.Drawing.Imaging.ColorPalette? ColorPalette does not have a constructor, and the Entries property is ReadOnly. How are we supposed to specify a palette other than the...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.