I want to pick points on the picture. These points converge into a recta.
Later i will use this rectange for picture cropping....
Firstly how can I draw this recta.?
I want to pick points on the picture. These points converge into a recta.
Later i will use this rectange for picture cropping....
Firstly how can I draw this recta.?
Hi PaulDares-7770,
You can use Graphics.DrawRectangle method to draw a rectangle in pictureBox paint event.
Here is my test code you can refer to.
private Point clickLast = Point.Empty;
private Point clickPrev = Point.Empty;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
clickPrev = clickLast;
clickLast = new Point(e.X,e.Y);
if (clickPrev == Point.Empty) return;
pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int h = clickLast.Y - clickPrev.Y;
int w = clickLast.X - clickPrev.X;
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 3);
e.Graphics.DrawRectangle(pen, clickPrev.X, clickPrev.Y, w, h);
clickLast = Point.Empty;
}
Test result:
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thanks was just the answer I was looking for. It worked very well for me.
Just use the grafikmat.DrawRectangle() to draw your rectangle.
Not sure why you need to set width of matbmp to (bmp.Width / 4) and set cutimg.X to (bmp.Width / 2). You may want to verify that.
Thanks Yes, the code needs to be changed. So how do I pick two points and draw a rectangle? With Mouseclick? I still can't do this....
Your pictureBox1 receives mouse events to save that start point, and then calculate the width and height of rectangle to be drawn with the end point, Now just use the .DrawRectangle() function I mentioned to draw it on the shadow copy of image you created, and replace the drawn image to the picturebox (I see you've done this step on code)
If you want to draw a Selection Rectangle, you can find samples in some archived threads , like for example :
draw selection rectangle (VB, ~same code in C#)
Drag Selection Box
Adding Drag/Drop/Resizable Selection Rectangle to Image Editor
etc...
and the old MSDN KB :
How to draw a rubber band rectangle or a focus rectangle in Visual C#
I will look at the sites you have posted. I hope I can do what I want. Thanks
7 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?