Hello,
here is my code piece. I know it's ugly written, but the idea is that I recieve an image over TCP IP and try to display it in a picturebox. -
try
-
{
-
WriteMessage("Image Data recieved.");
-
int size = m_client.Available;
-
WriteMessage("Image Size: " + size.ToString() + " bytes.");
-
byte[] buffer = new byte[size];
-
nstream.Read(buffer, 0, size);
-
-
MemoryStream mstream = new MemoryStream();
-
mstream.Write(buffer, 0, size);
-
-
Image img = Image.FromStream(mstream);
-
-
m_display.Image = img;
-
-
img.Dispose();
-
mstream.Close();
-
-
// Ask next image.
-
WriteMessage("Asking next image.");
-
byte[] request = Encoding.ASCII.GetBytes(txt_message.Text);
-
-
if (nstream.CanWrite)
-
{
-
nstream.Write(request, 0, request.Length);
-
}
-
else
-
{
-
WriteMessage("Can't write next request.");
-
}
-
}
-
catch (Exception Ex)
-
{
-
WriteMessage(Ex.Message);
-
}
-
I'm getting an ArgumentException thrown here and I can't seem to catch , although the code is surrounded with try-catch blocks.
The argument exception complains about an invalid parameter is beeing related to image width. At least thats all I can tell from the exception.
The function itself it beeing called at a regular interval using a Threading.Timer class.
EDIT:
did some debugging, the image get's transfered correctly. Saved it to disk and it displays correctly. So no idea where the problem is comming from.
11 4737
Here's the details of the exception -
System.ArgumentException was unhandled
-
Message=Parameter is not valid.
-
Source=System.Drawing
-
StackTrace:
-
at System.Drawing.Image.get_Width()
-
at System.Drawing.Image.get_Size()
-
at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
-
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
-
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
-
at System.Windows.Forms.Control.WmPaint(Message& m)
-
at System.Windows.Forms.Control.WndProc(Message& m)
-
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
-
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
-
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
-
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
-
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
-
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
-
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
-
at System.Windows.Forms.Application.Run(Form mainForm)
-
at VTTest.Program.Main() in E:\Source Code\CurrentRelease\Visual Studio\UnitTests\VTTest\VTTest\Program.cs:line 18
-
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
-
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
-
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
-
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
-
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
-
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
-
at System.Threading.ThreadHelper.ThreadStart()
-
InnerException:
-
So if I understand this correctly, the problem is related with drawing the image on the display?
You are disposing the image before m_display has time to render it, let the garbage collector do it for you and you may find it works. Also, make sure to catch more specific exceptions, using the base Exception class means that you get only a general handler for the exception.
Best of luck :)
Aimee.
Why is the solution always this bloody simple.....
I have removed the dispose and it works....Still getting an invalid parameter exception now and then but the images get displayed at least.
I've noticed that I have a serious "lag" on the display and alot of the images get corrupt on the display. Is this a transfer issue between server & client, or am I simply overwriting them too fast?
GaryTexmo 1,501
Recognized Expert Top Contributor
Oh this exception.. ugh, yea I've encounters this too.
The details are fuzzy, but I think when you dispose that object it destroys something the memory stream is holding onto.
Something else I just noticed, should you be using the Image class, or its base class Bitmap?
GaryTexmo 1,501
Recognized Expert Top Contributor
Oops, nevermind my last post. I misread and thought you were doing something else.
That said, I don't think you can close the memory stream. When I was fooling around with loading images and I closed the memory stream, I would get that exception... I think. I'm going to have to dig through my example project.
I'll give it a go without closing or disposing stuff. Might move them to class members and simply reuse them.
Currently I'm using the Image base class because I'm loading jpeg from a TCP stream.Whether or not these remain jpeg I don't know yet.
I'm simply trying to emulate a videostream, because I don't want to use a third-party component to render avi streams.
In theory this should work just as well :S
One question, are you loading them one by one? or are you buffering a couple at a time before playing?
Stupid question I know, but have to ask :$
I'm loading them one by one.
The idea is that the client requests an Image, this image gets loaded & transfered. Then the client displays the image and sends the next request.
So it's practicly the bandwith + client processing speed that determine the speed of the transfer.
I have set the NoDelay option to true on my TcpListener/Client to make sure that the transfers don't have to wait for a full buffer.
Update:
Setting the NoDelay on the client to true, but false on the server seems to produce the fastest results at the moment.
UPDATE:
Well after playing around with various settings and making a lot of configurable, I've found some conclusions:
- The client polls the line every 10ms
- The server polls the line every 75ms
- The client sends a request and receives image data.
- The client needs around 16ms to send a request, get a reply and render the whole image.
- The server needs 100ms to complete a request, because the UDP response from the third applications takes so long.
Is it correct to conclude that the TCP connection works as intended, but that the following issues occur:
- Server gets slowed down due the UDP taking so long
- THe client 'lags' because I overwrite the image faster then its beeing displayed
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: nrhayyal |
last post by:
hi all,
i am facing a problem in catching an exception which is uncaught in any
of the catch block.
not doing so will gives me coredump.
I tried by rewriting set_unexpected() and set_terminate()...
|
by: meaneyedcat |
last post by:
When I call addField(), my table appears to be populated correctly
with a new row in the table with all the required fields. However,
when I call delete row on any new rows that have been created,...
|
by: c.prerovsky |
last post by:
Hi there,
I started messing around with JavaScript OOP a few days ago and still
can't get this one to work. There are many things wich keep confusing
me, eg. the various ways to define a class...
|
by: -Lost |
last post by:
Error: uncaught exception: " nsresult: "0x80004001
(NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame ::
file:///D:/sites/_test/js/iterate_document.htm :: <TOP_LEVEL:: line 15" data: no]
Line 15...
|
by: Plater |
last post by:
I am using the XMLHttpRequest to send a request every 5ish seconds or so.
Everything works fine until I take the server down that the object is trying to retrieve data from.
Then the firefox...
| |
by: xhunter |
last post by:
Hi,
I have written my code to load some content through ajax, which works perfectly,
then I thought of adding a timeout to retry the action in case it has failed or something.
here is the code...
|
by: George2 |
last post by:
Hello everyone,
Just want to check whether my understanding is correct,
Both (1) and (2) only covers Windows C++ platform.
1. If there is uncaught exception, destructor is not ensured to...
|
by: josephx |
last post by:
Hello,
I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's...
|
by: friend |
last post by:
Error: uncaught exception: " nsresult:
"0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://manimekalai/VulnMgmt/scanfi/crs_source/vulnupdate/latest.php?vulnerability=2451
::...
|
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,...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |