C#中的神奇套索工具 [英] Magical Lasso tool in C#

查看:148
本文介绍了C#中的神奇套索工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我的Windows窗体中有一个图片框.
现在我想要的是,如果用户单击图片框上的某个位置,该程序会自动识别它的整个形状,如圆形或三角形和透明的其余图像,即Photoshop中神奇的套索工具的功能.
关于如何在c#

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#

推荐答案

中执行此操作的任何建议魔术套索工具需要一些与图像识别相关的难以实现的算法.通过使用类PictureBox,您已经走错了路.完全没有帮助.请查看我过去的答案:
如何从旧图纸中清除面板 [ ^ ],
在C#中绘制矩形 [在图片框内添加图片 [在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [ http://en.wikipedia.org/wiki/GIMP [ http://www.gimp.org/ [ ^ ].

您可以在此处获取源代码:
http://www.gimp.org/downloads/ [
现在,要在您的.NET项目中使用该代码,您只需了解其工作原理并编写代码(或从GIMP进行翻译)即可.如果要使用本机C ++代码,则可以通过P/Invoke或开发C ++/CLI混合模式包装器库来实现.

如果您需要学习P/Invoke,请从这里开始:
http://en.wikipedia.org/wiki/P/Invoke [ http://msdn.microsoft.com/en-us/library/Aa712982 [ ^ ].

此CodeProject也可能有用:基本P/调用 [ 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
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(...))[^].



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


这篇关于C#中的神奇套索工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆