|
Hi
I have a server app which handles multiple Ethernet camera. The server sends a video streams to a client application which is then displayed on screen. The problem is that I am recieving corrupt frames quite regularly at the client end. An example of a frame is below,
[][Corrupt frame]
I am using TCP to send the images. Anyone got any ideas of what could be causing this?
Thanx
|
|
|
|
|
The image shown seems to contain the superposition of three images.
Maybe those three subimages are real, and the purpose of the system is to offer such superposition. If not, then something is wrong.
Nobody can tell what is wrong when:
- we don't know what you want the system to do (if there are three camera's, where should the three images go?)
- we don't know anything about how your system has been implemented.
Maybe the right answer is: you have a bad pointer in line 42.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
modified on Monday, May 24, 2010 4:07 PM
|
|
|
|
|
Luc Pattyn wrote: bad pointer in line 42
OMG Luc you kill me.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Sorry for the lack of info. Ill try to explain what I am doing.
I have a server application that is connected to mutltiple ethernet cameras. The server application is responsible for recording video and redirecting the camera streams. The client application is used to view the live camera streams and recorded video. When sending the live stream from the server to the client applications I get the wierd behavour shown in the image. The image shows frames from 2 cameras.
I was thinking that it was caused by a race condition somewhere at first. But after testing the applications over a busier network the corruption of the frames seems to increase. So maybe it has somthing to do with TCP.
|
|
|
|
|
Hi,
I have the picture box in which i draw the rectangle (using graphics paint) and inside that rectangle I typed some name using label box and stored the work, have done.(for this please ref: http://www.codeproject.com/Messages/3474995/How-can-save-picturebox-image-using-menustrip.aspx[])
When I opened the saved Image the position of text I typed in the label box not in the position where I try to place (on screen). It's saving the text in some other position.
How to co-ordinate the resolution using c#.
Image bac;
Bitmap myBitmap;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (mybitmap == null)
{
mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
}
rect = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
{
rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
this.Invalidate();
break;
}
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (mybitmap == null)
{
return;
}
using (Pen pen = new Pen(Color.Red, 2))
{
using (Graphics g = Graphics.FromImage(mybitmap))
{
e.Graphics.DrawRectangle(pen, rect);
if (label1.TextAlign == ContentAlignment.TopLeft)
{
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Bounds);
g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Bounds);
mybitmap.PixelFormat);
}
else if (label1.TextAlign == ContentAlignment.TopCenter)
{
SizeF size = e.Graphics.MeasureString(label1.Text, label1.Font);
float left = ((float)this.Width + label1.Left) / 2 - size.Width / 2;
RectangleF rect1 = new RectangleF(left, (float)label1.Top, size.Width, label1.Height);
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect1);
}
else
{
SizeF size = e.Graphics.MeasureString(label1.Text, label1.Font);
float left = (float)label1.Width - size.Width + label1.Left;
RectangleF rect1 = new RectangleF(left, (float)label1.Top, size.Width, label1.Height);
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect1);
}
}
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mybitmap != null)
{
SaveFileDialog SaveFD1 = new SaveFileDialog();
SaveFD1.FileName = "";
SaveFD1.InitialDirectory = "C";
SaveFD1.Title = "save file Name";
SaveFD1.Filter = "JPG|*.jpg|Bmp|*.bmp";
if (SaveFD1.ShowDialog() == DialogResult.OK)
{
System.IO.Stream filename = (System.IO.FileStream)SaveFD1.OpenFile();
int r = SaveFD1.FileName.Length;
for (int r1 = 0; r1<=r;)
{
if (SaveFD1.FileName[r1] != '.')
r1++;
else
{
r = r1;
break;
}
}
if (SaveFD1.FileName[++r] == 'j')
{
using (Graphics g = Graphics.FromImage(bac))
{
g.DrawImage(mybitmap, 0, 0);
}
bac.Save(filename, ImageFormat.Jpeg);
}
else if (SaveFD1.FileName[r] == 'b')
{
using (Graphics g = Graphics.FromImage(bac))
{
g.DrawImage(mybitmap, 0, 0);
}
bac.Save(filename, ImageFormat.Jpeg);
}
else
{
using (Graphics g = Graphics.FromImage(bac))
{
g.DrawImage(mybitmap, 0, 0);
}
bac.Save(filename, ImageFormat.Png);
}
filename.Close();
}
}
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFD.FileName = "";
OpenFD.Title = "open image";
OpenFD.InitialDirectory = "C";
OpenFD.Filter = "JPEG|*.jpg|Bmp|*.bmp|All Files|*.*.*";
if (OpenFD.ShowDialog() == DialogResult.OK)
{
file = OpenFD.FileName;
bac = Image.FromFile(file);
pictureBox1.Image = bac;
pictureBox1.Invalidate();
}
}
|
|
|
|
|
Hi,
IMO that is all wrong from the very start. A Control_Paint handler is supposed to paint the control to the screen, yours modifies an image and does not paint to the screen at all.
This is how I would probably tackle this:
1. I'd have a Compose method that creates the composite image, by allocating a Bitmap of the right size, calling CreateGraphics() on it; then using that Graphics to paint the image and the rectangle and the text into the Bitmap.
2. I would call the Compose method when the composition has to change, which is unrelated to the user deciding to see, not see, scroll it.
3. Then show that Bitmap to the user; as I don't like PictureBox much, I probably would use a Panel of the right size, and use Graphics.DrawImage in its Paint handler.
The main advantages of such approach are:
- all parts of the composition are dealt with in the same way, they share the coordinate system, the mouse actions (if any), etc. No hassle with a PictureBox that may zoom/pan/center/fill the image, and treat everything else you draw on top of it in a different way.
- the composite image is available at all times; you can easily save it to disk, and to a database.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
1. I'd have a Compose method that creates the composite image, by allocating a Bitmap of the right size, calling CreateGraphics() on it; then using that Graphics to paint the image and the rectangle and the text into the Bitmap.
for this have done the below code in mouse down event
if (mybitmap == null)
{
mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
}
is this correct..
and I can't get the 2 and 3rd point. I have place the picture box in side the panel.
Please explain with ex:
I am new to C# (i am learning guy)
|
|
|
|
|
Nivas82 wrote: mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
That probably is correct and unnecessary, I've never felt a need to do it like that; a simple new Bitmap(pictureBox1.Width, pictureBox1.Height) is sufficient in almost all cases.
If you're new at something, I suggest you read and study the subject. I always recommend studying books, as they tend to be consistent and thorough; I do not recommend a particular book though, that depends on your background and the writing style you prefer.
Once the basics are covered, I recommend reading articles, CodeProject has a lot of very good ones. I did create a little one on graphics you migt find useful: http://www.perceler.com/articles1.php?art=animation1[^]. It does not involve a PictureBox, as I consider that a stupid and pretty useless Control.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi,
I got the output as i expected. I Place the picture box size with original image size and its works as expected (initially tried with picture box size mode as "zoom") .
replace or add the below code in the previous once at appropriate areas.
In open tool strip menu
pictureBox1.Image = image;
pictureBox1.Size = image.Size;
piturebox paint event
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect);
g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect);
in Save tool tip
bac = pictureBox1.Image;
using (Graphics g = Graphics.FromImage(bac))
{
g.DrawImage(mybitmap,0,0);
}
bac.Save(filename, ImageFormat.Jpeg);
modified on Saturday, May 29, 2010 2:12 AM
|
|
|
|
|
Or you can add the original image width and height to bitmap (without changing the size of the picture box).
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (mybitmap == null)
{
mybitmap = new Bitmap(sz.Width, sz.Height);
}
rect = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
|
|
|
|
|
Hi Experts,
First of all sorry for not figuring out a proper subject line for the problem i am facing.
Consider that I have 3 projects with me.
1. DefineEnum
2. UseEnumInMethod
3. UseMethod
The first project defines an enum just like any other project i.e.
public enum MyEnum
{
value1 = 0,
value2 = 1
}
The second project i.e. "UseEnumInMethod" has a method defined in it which has the above mentioned enum as a type to its parameter as
public void UseDefinedEnums(MyEnum _enum)
{
}
I can get the "MyEnum" as a type to the parameter of the method here by adding the project reference of "DefineEnum" in project "UseEnumInMethod".
Now when i want to use the above method in my third project i.e. in "UseMethod" I have to give the reference of both the projects 1 and 2 in the 3rd project if I want to use it as follows.
public void Test()
{
UseDefinedEnums(MyEnum.value1);
}
My question here is, is it possible to avoid giving the reference of the 1st project in the 3rd project and still avail the above functionality?
Anyone Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
dashingsidds wrote: is it possible to avoid giving the reference of the 1st project in the 3rd project and still avail the above functionality?
Consider the problem, if you do not give the reference then how is the compiler to determine what you mean when you refer to a MyEnum variable?
It's time for a new signature.
|
|
|
|
|
Hi Richard,
That is the exact challenge i am facing. In my scenario i cannot give the reference of the 1st project in the third project as i have mentioned. And if I do not give the reference, the third project will not know if the enum "MyEnum" actually exists just as you have mentioned.
Maybe i need to create a wrapper in the second project which will expose the enum declared in the first project but i am unable to figure out how am i suppose to go about doing that.
Regards,
Samar
|
|
|
|
|
dashingsidds wrote: i cannot give the reference of the 1st project in the third project
OK, but you have not explained why you cannot do this, or what problem you are trying to solve. Maybe if you explain a bit more about what you are trying to do we can offer some suggestions.
It's time for a new signature.
|
|
|
|
|
dashingsidds wrote: i cannot give the reference of the 1st project in the third project
You'll have a hard time defending that statement.
|
|
|
|
|
Hi PIEBALD,
I can defend that.
My team here is building a framwork which will have a single assembly which will be used in further projects. The requirement from the client here is this framework should contain just 1 assembly and not more than that. Now while building this framwork we realised that we had to create 2 assemblies instead of 1 (please dont ask why ) , in my example above, project 1 and 2. Now just as i said we cannot give 2 assemblies to the client which will reference in his project that is why all this head-breaking is goin on here.
I hope i have defended my stance well.
Regards,
Samar
|
|
|
|
|
You didn't defend "cannot" -- the actual inability to do it; you merely stated a prohibition not to do it.
Then you must have everything in one assembly.
|
|
|
|
|
dashingsidds wrote: is it possible to avoid giving the reference of the 1st project in the 3rd project and still avail the above functionality?
No. If you try to use the 2nd project in the 3rd project, then ALL of the items that the 2nd project is dependent on must be satisfied in the 3rd project.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hmm. I see your point Pete.
But just a thought, is it possible that we create a wrapper (a class maybe) in the second project which will expose the functionality given in the first project?? The only problem here is i am unable to figure how am i suppose to do that!!
Regards,
Samar
|
|
|
|
|
If you are defining it in your 2nd project, then what purpose does the 1st one serve?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
It is possible, but notice, that you have (in the project 2, your "wrapper") a public method that takes enum you want to hide as a parameter. Therefore project 3 must know what this enum is (event if it didn't use the method). If you redesign the middle layer, so it doesn't expose your enum anywhere it should work probably work as you want, but a question arrises if it's worth the effort.
But, there's "but". Even if you redesign it, and you won't have reference to project 1 from project 3, output of the project 1 (dll) will still make it to the output of the application.
|
|
|
|
|
dashingsidds wrote: My question here is, is it possible to avoid giving the reference of the 1st project in the 3rd project and still avail the above functionality?
No. Unless you use a web service to expose your first project. You would then be generating a proxy for your this class in wherever you want to consume your web service.
My signature "sucks" today
|
|
|
|
|
dashingsidds wrote: Now when i want to use the above method in my third project i.e. in "UseMethod" I have to give the reference of both the projects 1 and 2 in the 3rd project if I want to use it as follows.
public void Test()
{
UseDefinedEnums(MyEnum.value1);
}
My question here is, is it possible to avoid giving the reference of the 1st project in the 3rd project and still avail the above functionality?
Hi Samar,
You can't do it as you are using both the two projects inside the third one. You must have to add the reference of the two projects in the third one.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
This is analogous:
here is a method that calculates the square of a number:
public static Number Square(Number aNumber) {...}
now start using it.
BTW I will not tell you what Number is.
You should see immediately it can't be done, how can you use something when it relies on stuff that is not available?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|