Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi
My question is that i am having video stream from my webcam.i am displaying it on my picture box.Now i want user to to click on four locations and i want a rectangle drawn on using those four locations i-e first click will be the starting point so on.
I am a beginner so please excuse if you feel its too simple.I can draw a rectangle using hard coded locations.Following is the code i have in my event handler that has the new frame.
C#
Pen pen = new Pen(Color.Red, 2);
Graphics g = Graphics.FromImage(bitmap);
g.DrawRectangle(pen, 30, 30, 60, 30);

but as you see i have hard coded initial x,y,width,height i want them to be user defined clicks.

regards
Posted
Comments
Sergey Alexandrovich Kryukov 12-Nov-12 1:29am    
What do you want it to draw on, ultimately, on a screen or a bitmap? If a bitmap, and the mouse is on the screen, how it supposed to be?
--SA
loraloper_22 12-Nov-12 1:46am    
i want to draw it on the bitmap now when user clicks on four locations i want to store them
Sergey Alexandrovich Kryukov 12-Nov-12 2:27am    
Do you mean that a bitmap is rendered in some control, than -- what? Do you need to draw a rectangle as you move the mouse? Otherwise you would not see the data. And are you sure you really want to draw on a bitmap? What's the goal of all of it?
--SA
loraloper_22 12-Nov-12 2:34am    
I have done it anyways.The goal was to draw an out of bound region when ever an object moves into it raise an alarm.
regards

1 solution

First off, you don't want four locations - they will not necessarily describe a rectangle, or even a parallelogram. Two points define a rectangle: either TLHC and BRHC or TRHC and BLHC is sufficient.

Exactly how you pick up the mouse locations will depend on where you are drawing your bitmap: if it is on a form surface then just handle the Form.MouseDown or Form.MouseClick event - they both give your the mouse coordinates as part of the MouseEventArgs parameter.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900