Click here to Skip to main content
13,056,229 members (70,875 online)
Rate this:
Please Sign up or sign in to vote.

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.
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.

Posted 11-Nov-12 19:04pm
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?
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
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?
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.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170728.5 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100