Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hey guys.
I have a picture box in my windows form.
Now i want if user click on a place on picture box the program automaticaally identifies the whole shape of it like round or ractangle and transparent rest of image i.e functionallity of magical lasso tool in Photoshop.
Any Suggestion of how to do this in c#
Posted
Comments
Chandrashekar SK 8-Oct-12 7:50am    
What you are talking is based on Image processing. No Idea. Lets wait for experts..
Hetal Jariwala 8-Oct-12 8:12am    
Yup
Sergey Alexandrovich Kryukov 8-Oct-12 15:34pm    
Well, image recognition. I think you is well beyond the format of Quick Questions & Answers. This is a serious problem. Besides, any thinkable algorithm cannot perfectly solve the problem; and Photoshop's is not perfect as well.
--SA
Richard MacCutchan 8-Oct-12 9:11am    
Go to the articles section; there are many examples of image processing that will help you.

1 solution

A magic lasso tool needs some hard-to-implement algorithm related to image recognition. And you already took a wrong path by using the class PictureBox. It won't be helpful at all. Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^];
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

[EDIT]

You can use open-source GIMP to find out a couple of similar algorithms:
http://en.wikipedia.org/wiki/GIMP[^],
http://www.gimp.org/[^].

You can get source code here:
http://www.gimp.org/downloads/[^].

First, try how it works. Even though there are no exact "lasso tool" (the tool shown under the "lasso" pictogram is different, just a free-hand selection), there are some similar tools: "Fuzzy Select Tool" (a.k.a. "Magic Wand"), "Select by Color Tool" and "Scissors Select Tool" (the closest to "Lasso Select").

Now, to use the code in your .NET project, you can simply learn how it works and write your code (or translate from GIMP). If you want to use the native C++ code, you can do it either through P/Invoke or by developing a C++/CLI mixed-mode wrapper library.

If you need to learn P/Invoke, start from here:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/en-us/library/Aa712982[^].

This CodeProject can also be useful: Essential P/Invoke[^].

One alternative to P/Invoke is to use C++/CLI mixed-mode (managed+unmanaged) project. This project could build a DLL required by the global hooks, but it can contain some managed wrapper CLI code, so, from the standpoint of your .NET application, you can use it as a regular .NET assembly, that is, reference it. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[^],
http://msdn.microsoft.com/en-us/library/3bstk3k5[^].

—SA
 
Share this answer
 
v2
Comments
Nelek 12-Oct-12 6:53am    
OP is asking you: "Can u suggest any other links?" adding a non-solution message
Sergey Alexandrovich Kryukov 12-Oct-12 11:50am    
Thank you for removing the trash, Nelek.

OK, I remembered yet another possibility; please see the update of my answer, after [EDIT].

I will possibly add more links, if I can, but only if you explain what's wrong with those you already have. You should also understand, that you hardly can hope for finding of a complete solution of the lasso selection of good quality. If some company has really valuable code, chances are, it's kept in secret. And, unfortunately, we don't have resources for development of such thing. By the way, even when I did image processing, this algorithm was not my first priority, be far -- the results are always questionable, but the work is very difficult.

--SA
Nelek 14-Oct-12 6:35am    
You are welcome. :)
Hetal Jariwala 25-Oct-12 7:41am    
I cann't get ur solution
Nelek 25-Oct-12 13:28pm    
Then you should ask the one answering you :)

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