Click here to Skip to main content
15,742,477 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
I'm searching for an open source C# selection tool that functions like Select in MS Paint. You establish a selection box and can then adjust the size of it with your mouse. This allows you to set a very precise crop area on the image.

I've looked through a bunch of Code Project articles without finding such code, although Günther M. Foidl's Cropping Images takes me halfway there. The missing piece is resizing the selection box prior to cloning the cropped portion of the image.

Any suggestions?

(Edited: 3/3/14 8:25PM)
Posted
Updated 3-Mar-14 16:26pm
v2
Comments
Sergey Alexandrovich Kryukov 3-Mar-14 19:30pm    
It sounds weird. What prevents you from just reading standard MSDN documentation? What to search for, the most basic image operations? :-)
—SA
pasztorpisti 4-Mar-14 4:36am    
What you need to do is writing a "Paint" custom control that draws the right portion of the image along with the "helper gizmos" of the currently used painting tool (crop selection). You will have to handle the drawing and the input of the custom control yourself to get the job done and "to bring a crop selection tool alive". That can be a lot of hard work and learning if you are writing a custom control for the first time.

I think CodeProject does have what you need: "A Resizable Graphical Rectangle" by Zebulon75018 [^]. It's not "commercial control quality beautiful," but, it's quite well done, and very responsive.

I am using this with FrameWork 4.5.1 with no problems. However, when I downloaded the author's source code, it would not compile in Visual Studio 2013 after conversion: missing ResX file and one other file. But, it was easy enough just to copy the 'UserRect Class, paste it into a new Class in a new VS Project, and use it.

To add a 'DoubleClick EventHandler to it, just find the 'SetPictureBox method, and add the EventHandler to the 'mPictureBox variable. I assume you'd find it easy to integrate your current cropping code with this Control.
 
Share this answer
 
Comments
Ed Gadziemski 8-Mar-14 17:13pm    
Thanks for the recommendation. That is very much what I am looking for.
The question was not about how to crop images. The question was about resizable selection boxes like the one in MS Paint.

Here is the solution I ended up modifying for my use: CRectTrackerCS[^]

Ed
 
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