Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
AccAOI
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 3589303b
由
LN
编写于
2019-06-18 10:18:31 +0800
浏览文件
选项
浏览文件
标签
下载
差异文件
1
2 个父辈
fe992407
860cabb5
全部展开
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
150 行增加
和
93 行删除
AOI/AoiMethod.cs
AOI/AoiProject.cs
AOI/rgb/AoiMethodRgb.cs
AOI/util/JsonUtil.cs
AccAOI/AccAOI.csproj
AccAOI/Form1.Designer.cs
AccAOI/Form1.cs
AccAOI/FrmAoiSetting.Designer.cs
AccAOI/FrmAoiSetting.cs
AccAOI/control/ABaseControl.Designer.cs
AccAOI/imageBoxEx/ImageBoxEx.cs
ImageBox/ImageBox.cs
ImageBox/ImageBox/ImageBoxSelectionMode.cs
AOI/AoiMethod.cs
查看文件 @
3589303
...
@@ -12,11 +12,26 @@ namespace AOI
...
@@ -12,11 +12,26 @@ namespace AOI
{
{
public
abstract
class
AoiMethod
public
abstract
class
AoiMethod
{
{
//public string FullTypeName { get; set; }
//public string PathDatas { get; set; }
public
string
MethodName
{
get
;
set
;
}
public
string
MethodName
{
get
;
set
;
}
/// <summary>
/// <summary>
/// 兴趣区域路径
/// 兴趣区域路径
/// </summary>
/// </summary>
public
GraphicsPath
RoiPath
;
[
Newtonsoft
.
Json
.
JsonIgnore
()]
public
GraphicsPath
RoiPath
{
get
;
set
;
}
public
PathData
GetRoiPathData
()
{
if
(
RoiPath
!=
null
)
{
return
RoiPath
.
PathData
;
}
return
null
;
}
public
abstract
ResultBean
Check
(
Image
standardImage
,
Image
imageToCheck
);
public
abstract
ResultBean
Check
(
Image
standardImage
,
Image
imageToCheck
);
...
...
AOI/AoiProject.cs
查看文件 @
3589303
...
@@ -22,7 +22,7 @@ namespace AOI
...
@@ -22,7 +22,7 @@ namespace AOI
/// <summary>
/// <summary>
/// 标准的Image
/// 标准的Image
/// </summary>
/// </summary>
p
rivate
Image
standardImage
{
get
;
set
;
}
p
ublic
Image
standardImage
{
get
;
set
;
}
/// <summary>
/// <summary>
/// 所有的AOI方法
/// 所有的AOI方法
...
@@ -68,7 +68,18 @@ namespace AOI
...
@@ -68,7 +68,18 @@ namespace AOI
Dictionary
<
string
,
string
>
projectMap
=
new
Dictionary
<
string
,
string
>();
Dictionary
<
string
,
string
>
projectMap
=
new
Dictionary
<
string
,
string
>();
string
base64ImgStr
=
Base64Util
.
ToBase64
(
this
.
standardImage
);
string
base64ImgStr
=
Base64Util
.
ToBase64
(
this
.
standardImage
);
projectMap
.
Add
(
"base64Img"
,
base64ImgStr
);
projectMap
.
Add
(
"base64Img"
,
base64ImgStr
);
string
methodMapJson
=
JsonUtil
.
SerializeObject
(
this
.
methodMap
);
var
mapForJson
=
new
Dictionary
<
string
,
string
>();
foreach
(
var
item
in
this
.
methodMap
)
{
JObject
obj
=
JObject
.
FromObject
(
item
.
Value
);
obj
.
Add
(
"FullTypeName"
,
item
.
Value
.
GetType
().
FullName
);
var
roiPathData
=
item
.
Value
.
GetRoiPathData
();
string
roiPathDataStr
=
JsonUtil
.
SerializeObject
(
roiPathData
);
obj
.
Add
(
"PathDataStr"
,
roiPathDataStr
);
string
jsonStr
=
JsonUtil
.
SerializeObject
(
obj
);
mapForJson
.
Add
(
item
.
Key
,
jsonStr
);
}
string
methodMapJson
=
JsonUtil
.
SerializeObject
(
mapForJson
);
projectMap
.
Add
(
"methodMap"
,
methodMapJson
);
projectMap
.
Add
(
"methodMap"
,
methodMapJson
);
JsonUtil
.
SerializeObjectToFile
(
projectMap
,
filePath
,
false
);
JsonUtil
.
SerializeObjectToFile
(
projectMap
,
filePath
,
false
);
}
}
...
@@ -79,7 +90,21 @@ namespace AOI
...
@@ -79,7 +90,21 @@ namespace AOI
string
base64Img
=
projectMap
[
"base64Img"
];
string
base64Img
=
projectMap
[
"base64Img"
];
this
.
standardImage
=
Base64Util
.
ToImage
(
base64Img
);
this
.
standardImage
=
Base64Util
.
ToImage
(
base64Img
);
string
methodMapJson
=
projectMap
[
"methodMap"
];
string
methodMapJson
=
projectMap
[
"methodMap"
];
this
.
methodMap
=
JsonUtil
.
DeserializeJsonToObject
<
Dictionary
<
string
,
AoiMethod
>>(
methodMapJson
);
var
jsonMap
=
JsonUtil
.
DeserializeJsonToObject
<
Dictionary
<
string
,
string
>>(
methodMapJson
);
foreach
(
var
item
in
jsonMap
)
{
JObject
obj
=
JObject
.
Parse
(
item
.
Value
);
string
fullTypeName
=
obj
.
Value
<
string
>(
"FullTypeName"
);
Type
t
=
Type
.
GetType
(
fullTypeName
);
JsonSerializer
serializer
=
new
JsonSerializer
();
StringReader
sr
=
new
StringReader
(
item
.
Value
);
object
o
=
serializer
.
Deserialize
(
new
JsonTextReader
(
sr
),
t
);
AoiMethod
aoiMethod
=
(
AoiMethod
)
o
;
string
PathDataStr
=
obj
.
Value
<
string
>(
"PathDataStr"
);
PathData
pathData
=
JsonUtil
.
DeserializeJsonToObject
<
PathData
>(
PathDataStr
);
aoiMethod
.
RoiPath
=
new
GraphicsPath
(
pathData
.
Points
,
pathData
.
Types
);
methodMap
.
Add
(
item
.
Key
,
aoiMethod
);
}
}
}
...
...
AOI/rgb/AoiMethodRgb.cs
查看文件 @
3589303
...
@@ -13,20 +13,20 @@ namespace AOI
...
@@ -13,20 +13,20 @@ namespace AOI
/// </summary>
/// </summary>
public
class
AoiMethodRgb
:
AoiMethod
public
class
AoiMethodRgb
:
AoiMethod
{
{
public
int
minR
=
1
;
public
int
minR
{
get
;
set
;
}
public
int
maxR
=
255
;
public
int
maxR
{
get
;
set
;
}
public
int
minG
=
1
;
public
int
minG
{
get
;
set
;
}
public
int
maxG
=
255
;
public
int
maxG
{
get
;
set
;
}
public
int
minB
=
1
;
public
int
minB
{
get
;
set
;
}
public
int
maxB
=
255
;
public
int
maxB
{
get
;
set
;
}
/// <summary>
/// <summary>
/// 抽取出的像素最小占比
/// 抽取出的像素最小占比
/// </summary>
/// </summary>
public
float
minRate
=
0
;
public
float
minRate
{
get
;
set
;
}
/// <summary>
/// <summary>
/// 抽取出的像素最大占比
/// 抽取出的像素最大占比
/// </summary>
/// </summary>
public
float
maxRate
=
100
;
public
float
maxRate
{
get
;
set
;
}
public
override
ResultBean
Check
(
Image
standardImage
,
Image
imageToCheck
)
public
override
ResultBean
Check
(
Image
standardImage
,
Image
imageToCheck
)
{
{
...
...
AOI/util/JsonUtil.cs
查看文件 @
3589303
...
@@ -66,6 +66,7 @@ namespace AOI
...
@@ -66,6 +66,7 @@ namespace AOI
T
t
=
o
as
T
;
T
t
=
o
as
T
;
return
t
;
return
t
;
}
}
/// <summary>
/// <summary>
/// 解析文件到生成对象实体
/// 解析文件到生成对象实体
/// </summary>
/// </summary>
...
...
AccAOI/AccAOI.csproj
查看文件 @
3589303
...
@@ -49,25 +49,25 @@
...
@@ -49,25 +49,25 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile Include="control\AioMarkControl.cs">
<Compile Include="control\AioMarkControl.cs">
<SubType>
UserControl
</SubType>
<SubType>
Form
</SubType>
</Compile>
</Compile>
<Compile Include="control\AioMarkControl.Designer.cs">
<Compile Include="control\AioMarkControl.Designer.cs">
<DependentUpon>AioMarkControl.cs</DependentUpon>
<DependentUpon>AioMarkControl.cs</DependentUpon>
</Compile>
</Compile>
<Compile Include="control\AoiBlobControl.cs">
<Compile Include="control\AoiBlobControl.cs">
<SubType>
UserControl
</SubType>
<SubType>
Form
</SubType>
</Compile>
</Compile>
<Compile Include="control\AoiBlobControl.Designer.cs">
<Compile Include="control\AoiBlobControl.Designer.cs">
<DependentUpon>AoiBlobControl.cs</DependentUpon>
<DependentUpon>AoiBlobControl.cs</DependentUpon>
</Compile>
</Compile>
<Compile Include="control\ABaseControl.cs">
<Compile Include="control\ABaseControl.cs">
<SubType>
UserControl
</SubType>
<SubType>
Form
</SubType>
</Compile>
</Compile>
<Compile Include="control\ABaseControl.Designer.cs">
<Compile Include="control\ABaseControl.Designer.cs">
<DependentUpon>ABaseControl.cs</DependentUpon>
<DependentUpon>ABaseControl.cs</DependentUpon>
</Compile>
</Compile>
<Compile Include="control\AoiRgbControl.cs">
<Compile Include="control\AoiRgbControl.cs">
<SubType>
UserControl
</SubType>
<SubType>
Form
</SubType>
</Compile>
</Compile>
<Compile Include="control\AoiRgbControl.Designer.cs">
<Compile Include="control\AoiRgbControl.Designer.cs">
<DependentUpon>AoiRgbControl.cs</DependentUpon>
<DependentUpon>AoiRgbControl.cs</DependentUpon>
...
@@ -88,9 +88,7 @@
...
@@ -88,9 +88,7 @@
<Compile Include="imageBoxEx\DragHandle.cs" />
<Compile Include="imageBoxEx\DragHandle.cs" />
<Compile Include="imageBoxEx\DragHandleAnchor.cs" />
<Compile Include="imageBoxEx\DragHandleAnchor.cs" />
<Compile Include="imageBoxEx\DragHandleCollection.cs" />
<Compile Include="imageBoxEx\DragHandleCollection.cs" />
<Compile Include="imageBoxEx\ImageBoxEx.cs">
<Compile Include="imageBoxEx\ImageBoxEx.cs" />
<SubType>Component</SubType>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AioMarkControl.resx">
<EmbeddedResource Include="control\AioMarkControl.resx">
...
...
AccAOI/Form1.Designer.cs
查看文件 @
3589303
namespace
AccAOI
using
Cyotek.Windows.Forms
;
namespace
AccAOI
{
{
partial
class
Form1
partial
class
Form1
{
{
...
@@ -40,8 +42,8 @@
...
@@ -40,8 +42,8 @@
this
.
minB
=
new
System
.
Windows
.
Forms
.
NumericUpDown
();
this
.
minB
=
new
System
.
Windows
.
Forms
.
NumericUpDown
();
this
.
maxB
=
new
System
.
Windows
.
Forms
.
NumericUpDown
();
this
.
maxB
=
new
System
.
Windows
.
Forms
.
NumericUpDown
();
this
.
labelCount
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
labelCount
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
imageBoxEx1
=
new
AccAOI
.
ImageBoxE
x
();
this
.
imageBoxEx1
=
new
ImageBo
x
();
this
.
imageBox
=
new
AccAOI
.
ImageBoxE
x
();
this
.
imageBox
=
new
ImageBo
x
();
this
.
panel1
.
SuspendLayout
();
this
.
panel1
.
SuspendLayout
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
maxR
)).
BeginInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
maxR
)).
BeginInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
minR
)).
BeginInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
minR
)).
BeginInit
();
...
@@ -203,7 +205,7 @@
...
@@ -203,7 +205,7 @@
//
//
// imageBoxEx1
// imageBoxEx1
//
//
this
.
imageBoxEx1
.
DragHandleSize
=
9
;
//
this.imageBoxEx1.DragHandleSize = 9;
this
.
imageBoxEx1
.
Location
=
new
System
.
Drawing
.
Point
(
475
,
50
);
this
.
imageBoxEx1
.
Location
=
new
System
.
Drawing
.
Point
(
475
,
50
);
this
.
imageBoxEx1
.
Name
=
"imageBoxEx1"
;
this
.
imageBoxEx1
.
Name
=
"imageBoxEx1"
;
this
.
imageBoxEx1
.
Size
=
new
System
.
Drawing
.
Size
(
230
,
159
);
this
.
imageBoxEx1
.
Size
=
new
System
.
Drawing
.
Size
(
230
,
159
);
...
@@ -212,7 +214,7 @@
...
@@ -212,7 +214,7 @@
// imageBox
// imageBox
//
//
this
.
imageBox
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
imageBox
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
imageBox
.
DragHandleSize
=
9
;
//
this.imageBox.DragHandleSize = 9;
this
.
imageBox
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
imageBox
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
imageBox
.
Name
=
"imageBox"
;
this
.
imageBox
.
Name
=
"imageBox"
;
this
.
imageBox
.
SelectionColor
=
System
.
Drawing
.
Color
.
Empty
;
this
.
imageBox
.
SelectionColor
=
System
.
Drawing
.
Color
.
Empty
;
...
@@ -258,7 +260,7 @@
...
@@ -258,7 +260,7 @@
#
endregion
#
endregion
private
System
.
Windows
.
Forms
.
Button
buttonOpen
;
private
System
.
Windows
.
Forms
.
Button
buttonOpen
;
private
ImageBox
Ex
imageBox
;
private
ImageBox
imageBox
;
private
System
.
Windows
.
Forms
.
Panel
panel1
;
private
System
.
Windows
.
Forms
.
Panel
panel1
;
private
System
.
Windows
.
Forms
.
Label
R
;
private
System
.
Windows
.
Forms
.
Label
R
;
private
System
.
Windows
.
Forms
.
NumericUpDown
maxR
;
private
System
.
Windows
.
Forms
.
NumericUpDown
maxR
;
...
@@ -269,7 +271,7 @@
...
@@ -269,7 +271,7 @@
private
System
.
Windows
.
Forms
.
NumericUpDown
maxG
;
private
System
.
Windows
.
Forms
.
NumericUpDown
maxG
;
private
System
.
Windows
.
Forms
.
NumericUpDown
minB
;
private
System
.
Windows
.
Forms
.
NumericUpDown
minB
;
private
System
.
Windows
.
Forms
.
NumericUpDown
maxB
;
private
System
.
Windows
.
Forms
.
NumericUpDown
maxB
;
private
ImageBox
Ex
imageBoxEx1
;
private
ImageBox
imageBoxEx1
;
private
System
.
Windows
.
Forms
.
Label
labelCount
;
private
System
.
Windows
.
Forms
.
Label
labelCount
;
}
}
}
}
...
...
AccAOI/Form1.cs
查看文件 @
3589303
...
@@ -64,10 +64,7 @@ namespace AccAOI
...
@@ -64,10 +64,7 @@ namespace AccAOI
Matrix
translateMatrix
=
new
Matrix
();
Matrix
translateMatrix
=
new
Matrix
();
translateMatrix
.
Translate
(
100
,
0
);
translateMatrix
.
Translate
(
100
,
0
);
RectangleF
region
=
imageBox
.
SelectionRegion
;
Image
threshImage
=
CutImage
(
imageBox
.
Image
,
imageBox
.
SelectionRegion
);
GraphicsPath
path
=
new
GraphicsPath
();
path
.
AddEllipse
(
region
);
Image
threshImage
=
CutImage
(
imageBox
.
Image
,
path
);
cutImage
=
threshImage
;
cutImage
=
threshImage
;
imageBoxEx1
.
Image
=
threshImage
;
imageBoxEx1
.
Image
=
threshImage
;
}
}
...
...
AccAOI/FrmAoiSetting.Designer.cs
查看文件 @
3589303
namespace
AccAOI
using
Cyotek.Windows.Forms
;
namespace
AccAOI
{
{
partial
class
FrmAoiSetting
partial
class
FrmAoiSetting
{
{
...
@@ -38,7 +40,7 @@
...
@@ -38,7 +40,7 @@
this
.
btnGetCameraImg
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnGetCameraImg
=
new
Asa
.
Theme
.
FlatButton
();
this
.
comType
=
new
Asa
.
Theme
.
FlatCombo
();
this
.
comType
=
new
Asa
.
Theme
.
FlatCombo
();
this
.
panAoi
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
panAoi
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
imageBox1
=
new
AccAOI
.
ImageBoxE
x
();
this
.
imageBox1
=
new
ImageBo
x
();
this
.
SuspendLayout
();
this
.
SuspendLayout
();
//
//
// aoiList
// aoiList
...
@@ -158,7 +160,7 @@
...
@@ -158,7 +160,7 @@
this
.
imageBox1
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Bottom
)
this
.
imageBox1
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Bottom
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
imageBox1
.
DragHandleSize
=
9
;
//
this.imageBox1.DragHandleSize = 9;
this
.
imageBox1
.
Location
=
new
System
.
Drawing
.
Point
(
625
,
40
);
this
.
imageBox1
.
Location
=
new
System
.
Drawing
.
Point
(
625
,
40
);
this
.
imageBox1
.
Name
=
"imageBox1"
;
this
.
imageBox1
.
Name
=
"imageBox1"
;
this
.
imageBox1
.
SelectionMode
=
Cyotek
.
Windows
.
Forms
.
ImageBoxSelectionMode
.
Rectangle
;
this
.
imageBox1
.
SelectionMode
=
Cyotek
.
Windows
.
Forms
.
ImageBoxSelectionMode
.
Rectangle
;
...
@@ -204,7 +206,7 @@
...
@@ -204,7 +206,7 @@
#
endregion
#
endregion
private
Asa
.
Theme
.
FlatList
aoiList
;
private
Asa
.
Theme
.
FlatList
aoiList
;
private
ImageBox
Ex
imageBox1
;
private
ImageBox
imageBox1
;
private
Asa
.
Theme
.
FlatButton
btnOpenPro
;
private
Asa
.
Theme
.
FlatButton
btnOpenPro
;
private
Asa
.
Theme
.
FlatButton
btnSavePro
;
private
Asa
.
Theme
.
FlatButton
btnSavePro
;
private
Asa
.
Theme
.
FlatButton
btnNewAoi
;
private
Asa
.
Theme
.
FlatButton
btnNewAoi
;
...
...
AccAOI/FrmAoiSetting.cs
查看文件 @
3589303
...
@@ -73,11 +73,6 @@ namespace AccAOI
...
@@ -73,11 +73,6 @@ namespace AccAOI
private
void
btnOpenPro_Click
(
object
sender
,
EventArgs
e
)
private
void
btnOpenPro_Click
(
object
sender
,
EventArgs
e
)
{
{
if
(
this
.
Img
==
null
)
{
MessageBox
.
Show
(
"清先打开图片"
);
return
;
}
System
.
Windows
.
Forms
.
OpenFileDialog
openDialog
=
new
System
.
Windows
.
Forms
.
OpenFileDialog
();
System
.
Windows
.
Forms
.
OpenFileDialog
openDialog
=
new
System
.
Windows
.
Forms
.
OpenFileDialog
();
openDialog
.
Title
=
"打开项目"
;
openDialog
.
Title
=
"打开项目"
;
openDialog
.
Filter
=
"(*.data)|*.data|(*.*)|*.*"
;
openDialog
.
Filter
=
"(*.data)|*.data|(*.*)|*.*"
;
...
@@ -188,7 +183,7 @@ namespace AccAOI
...
@@ -188,7 +183,7 @@ namespace AccAOI
if
(
method
.
RoiPath
!=
null
)
if
(
method
.
RoiPath
!=
null
)
{
{
currPath
=
method
.
RoiPath
;
currPath
=
method
.
RoiPath
;
imageBox1
.
SelectionRegion
=
method
.
RoiPath
.
GetBounds
()
;
imageBox1
.
SelectionRegion
=
method
.
RoiPath
;
Image
threshImage
=
CutImage
(
imageBox1
.
Image
,
currPath
);
Image
threshImage
=
CutImage
(
imageBox1
.
Image
,
currPath
);
cutImage
=
threshImage
;
cutImage
=
threshImage
;
...
@@ -227,6 +222,8 @@ namespace AccAOI
...
@@ -227,6 +222,8 @@ namespace AccAOI
if
(
Project
!=
null
)
if
(
Project
!=
null
)
{
{
aoiList
.
ItemClear
();
aoiList
.
ItemClear
();
imageBox1
.
Image
=
Project
.
standardImage
;
imageBox1
.
SelectionRegion
=
new
GraphicsPath
();
if
(
Project
.
methodMap
.
Count
>
0
)
if
(
Project
.
methodMap
.
Count
>
0
)
{
{
foreach
(
string
key
in
Project
.
methodMap
.
Keys
)
foreach
(
string
key
in
Project
.
methodMap
.
Keys
)
...
@@ -273,16 +270,17 @@ namespace AccAOI
...
@@ -273,16 +270,17 @@ namespace AccAOI
Matrix
translateMatrix
=
new
Matrix
();
Matrix
translateMatrix
=
new
Matrix
();
translateMatrix
.
Translate
(
100
,
0
);
translateMatrix
.
Translate
(
100
,
0
);
RectangleF
region
=
imageBox1
.
SelectionRegion
;
//RectangleF region = imageBox1.SelectionRegion;
currPath
=
new
GraphicsPath
();
//currPath = new GraphicsPath();
if
(
aoiControl
.
AreaType
.
Equals
(
1
))
//if (aoiControl.AreaType.Equals(1))
{
//{
currPath
.
AddRectangle
(
region
);
// currPath.AddRectangle(region);
}
//}
else
//else
{
//{
currPath
.
AddEllipse
(
region
);
// currPath.AddEllipse(region);
}
//}
currPath
=
imageBox1
.
SelectionRegion
;
Image
threshImage
=
CutImage
(
imageBox1
.
Image
,
currPath
);
Image
threshImage
=
CutImage
(
imageBox1
.
Image
,
currPath
);
cutImage
=
threshImage
;
cutImage
=
threshImage
;
...
...
AccAOI/control/ABaseControl.Designer.cs
查看文件 @
3589303
namespace
AccAOI.control
using
Cyotek.Windows.Forms
;
namespace
AccAOI.control
{
{
partial
class
ABaseControl
partial
class
ABaseControl
{
{
...
@@ -36,7 +38,7 @@
...
@@ -36,7 +38,7 @@
this
.
btnClearArea
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnClearArea
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnSetArea
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnSetArea
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnYuan
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnYuan
=
new
Asa
.
Theme
.
FlatButton
();
this
.
aoiImage
=
new
AccAOI
.
ImageBoxE
x
();
this
.
aoiImage
=
new
ImageBo
x
();
this
.
SuspendLayout
();
this
.
SuspendLayout
();
//
//
// panControl
// panControl
...
@@ -136,7 +138,7 @@
...
@@ -136,7 +138,7 @@
//
//
this
.
aoiImage
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)(((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
this
.
aoiImage
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)(((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
aoiImage
.
DragHandleSize
=
9
;
//
this.aoiImage.DragHandleSize = 9;
this
.
aoiImage
.
Location
=
new
System
.
Drawing
.
Point
(
9
,
53
);
this
.
aoiImage
.
Location
=
new
System
.
Drawing
.
Point
(
9
,
53
);
this
.
aoiImage
.
Name
=
"aoiImage"
;
this
.
aoiImage
.
Name
=
"aoiImage"
;
this
.
aoiImage
.
Size
=
new
System
.
Drawing
.
Size
(
288
,
182
);
this
.
aoiImage
.
Size
=
new
System
.
Drawing
.
Size
(
288
,
182
);
...
@@ -171,7 +173,7 @@
...
@@ -171,7 +173,7 @@
private
Asa
.
Theme
.
FlatPanel
panControl
;
private
Asa
.
Theme
.
FlatPanel
panControl
;
protected
Asa
.
Theme
.
FlatPanel
panParam
;
protected
Asa
.
Theme
.
FlatPanel
panParam
;
protected
Asa
.
Theme
.
FlatPanel
panResult
;
protected
Asa
.
Theme
.
FlatPanel
panResult
;
public
ImageBox
Ex
aoiImage
;
public
ImageBox
aoiImage
;
private
Asa
.
Theme
.
FlatButton
btnYuan
;
private
Asa
.
Theme
.
FlatButton
btnYuan
;
}
}
}
}
AccAOI/imageBoxEx/ImageBoxEx.cs
查看文件 @
3589303
此文件的差异被折叠,
点击展开。
ImageBox/ImageBox.cs
查看文件 @
3589303
...
@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms
...
@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms
[
DefaultProperty
(
"Image"
)]
[
DefaultProperty
(
"Image"
)]
[
ToolboxBitmap
(
typeof
(
ImageBox
),
"ImageBox.bmp"
)]
[
ToolboxBitmap
(
typeof
(
ImageBox
),
"ImageBox.bmp"
)]
[
ToolboxItem
(
true
)]
[
ToolboxItem
(
true
)]
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
public
class
ImageBox
:
VirtualScrollableControl
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
public
class
ImageBox
:
VirtualScrollableControl
{
{
#
region
Constants
#
region
Constants
...
@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms
...
@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms
private
ImageBoxSelectionMode
_selectionMode
;
private
ImageBoxSelectionMode
_selectionMode
;
private
RectangleF
_selectionRegion
;
private
GraphicsPath
_selectionRegion
=
new
GraphicsPath
()
;
private
bool
_shortcutsEnabled
;
private
bool
_shortcutsEnabled
;
...
@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms
...
@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms
this
.
DrawPixelGrid
(
e
.
Graphics
);
this
.
DrawPixelGrid
(
e
.
Graphics
);
}
}
// draw the selection
// draw the selection
if
(
this
.
SelectionRegion
!=
Rectangle
.
Empty
)
if
(
this
.
SelectionRegion
!=
null
&&
this
.
SelectionRegion
.
PointCount
>
0
)
{
{
this
.
DrawSelection
(
e
);
this
.
DrawSelection
(
e
);
}
}
...
@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms
...
@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms
/// </value>
/// </value>
[
Browsable
(
false
)]
[
Browsable
(
false
)]
[
DesignerSerializationVisibility
(
DesignerSerializationVisibility
.
Hidden
)]
[
DesignerSerializationVisibility
(
DesignerSerializationVisibility
.
Hidden
)]
public
virtual
RectangleF
SelectionRegion
public
virtual
GraphicsPath
SelectionRegion
{
{
get
{
return
_selectionRegion
;
}
get
{
return
_selectionRegion
;
}
set
set
...
@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms
...
@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms
result
=
null
;
result
=
null
;
if
(!
this
.
SelectionRegion
.
IsEmpty
)
var
bounds
=
this
.
SelectionRegion
.
GetBounds
();
if
(
this
.
SelectionRegion
.
PointCount
>
0
)
{
{
Rectangle
rect
;
if
(
bounds
.
Width
>
0
&&
bounds
.
Height
>
0
)
rect
=
this
.
FitRectangle
(
new
Rectangle
((
int
)
this
.
SelectionRegion
.
X
,
(
int
)
this
.
SelectionRegion
.
Y
,
(
int
)
this
.
SelectionRegion
.
Width
,
(
int
)
this
.
SelectionRegion
.
Height
));
if
(
rect
.
Width
>
0
&&
rect
.
Height
>
0
)
{
{
result
=
new
Bitmap
(
rect
.
Width
,
rect
.
Height
);
Bitmap
mask
=
new
Bitmap
(
this
.
Image
.
Width
,
this
.
Image
.
Height
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
mask
))
{
var
br
=
new
TextureBrush
(
this
.
Image
);
g
.
FillPath
(
br
,
this
.
SelectionRegion
);
}
var
dstRect
=
new
RectangleF
(
0
,
0
,
bounds
.
Width
,
bounds
.
Height
);
var
srcRect
=
new
RectangleF
(
bounds
.
X
,
bounds
.
Y
,
bounds
.
Width
,
bounds
.
Height
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
result
))
using
(
Graphics
g
=
Graphics
.
FromImage
(
result
))
{
{
g
.
DrawImage
(
this
.
Image
,
new
Rectangle
(
Point
.
Empty
,
rect
.
Size
),
rect
,
GraphicsUnit
.
Pixel
);
result
=
new
Bitmap
((
int
)
bounds
.
Width
,
(
int
)
bounds
.
Width
);
g
.
DrawImage
(
mask
,
dstRect
,
srcRect
,
GraphicsUnit
.
Pixel
);
}
}
return
result
;
}
}
}
}
...
@@ -2629,20 +2637,11 @@ namespace Cyotek.Windows.Forms
...
@@ -2629,20 +2637,11 @@ namespace Cyotek.Windows.Forms
}
}
/// <summary>
/// <summary>
/// Creates a selection region which encompasses the entire image
/// </summary>
/// <exception cref="System.InvalidOperationException">Thrown if no image is currently set</exception>
public
virtual
void
SelectAll
()
{
this
.
SelectionRegion
=
new
RectangleF
(
PointF
.
Empty
,
this
.
ViewSize
);
}
/// <summary>
/// Clears any existing selection region
/// Clears any existing selection region
/// </summary>
/// </summary>
public
virtual
void
SelectNone
()
public
virtual
void
SelectNone
()
{
{
this
.
SelectionRegion
=
RectangleF
.
Empty
;
this
.
SelectionRegion
=
new
GraphicsPath
()
;
}
}
/// <summary>
/// <summary>
...
@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms
...
@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms
/// </param>
/// </param>
protected
virtual
void
DrawSelection
(
PaintEventArgs
e
)
protected
virtual
void
DrawSelection
(
PaintEventArgs
e
)
{
{
RectangleF
rect
;
e
.
Graphics
.
SetClip
(
this
.
GetInsideViewPort
(
true
));
e
.
Graphics
.
SetClip
(
this
.
GetInsideViewPort
(
true
));
rect
=
this
.
GetOffsetRectangle
(
this
.
SelectionRegion
);
GraphicsPath
newPath
=
new
GraphicsPath
(
this
.
SelectionRegion
.
PathPoints
,
this
.
SelectionRegion
.
PathTypes
);
Matrix
matrix
=
new
Matrix
();
matrix
.
Scale
((
float
)
this
.
ZoomFactor
,
(
float
)
this
.
ZoomFactor
);
newPath
.
Transform
(
matrix
);
var
viewport
=
this
.
GetImageViewPort
();
var
offsetX
=
viewport
.
Left
+
this
.
Padding
.
Left
+
this
.
AutoScrollPosition
.
X
;
var
offsetY
=
viewport
.
Top
+
this
.
Padding
.
Top
+
this
.
AutoScrollPosition
.
Y
;
matrix
=
new
Matrix
();
matrix
.
Translate
(
offsetX
,
offsetY
);
newPath
.
Transform
(
matrix
);
//rect = this.GetOffsetRectangle(this.SelectionRegion);
using
(
Brush
brush
=
new
SolidBrush
(
Color
.
FromArgb
(
128
,
this
.
SelectionColor
)))
using
(
Brush
brush
=
new
SolidBrush
(
Color
.
FromArgb
(
128
,
this
.
SelectionColor
)))
{
{
e
.
Graphics
.
FillRectangle
(
brush
,
rect
);
e
.
Graphics
.
FillPath
(
brush
,
newPath
);
}
}
using
(
Pen
pen
=
new
Pen
(
this
.
SelectionColor
))
using
(
Pen
pen
=
new
Pen
(
this
.
SelectionColor
))
{
{
e
.
Graphics
.
DrawRectangle
(
pen
,
rect
.
X
,
rect
.
Y
,
rect
.
Width
,
rect
.
Height
);
//e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
e
.
Graphics
.
DrawPath
(
pen
,
newPath
);
}
}
e
.
Graphics
.
ResetClip
();
e
.
Graphics
.
ResetClip
();
...
@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms
...
@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms
{
{
EventHandler
<
EventArgs
>
handler
;
EventHandler
<
EventArgs
>
handler
;
switch
(
this
.
SelectionMode
)
//
switch (this.SelectionMode)
{
//
{
case
ImageBoxSelectionMode
.
Zoom
:
//
case ImageBoxSelectionMode.Zoom:
if
(
this
.
SelectionRegion
.
Width
>
SelectionDeadZone
&&
this
.
SelectionRegion
.
Height
>
SelectionDeadZone
)
//
if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
{
//
{
this
.
ZoomToRegion
(
this
.
SelectionRegion
);
//
this.ZoomToRegion(this.SelectionRegion);
this
.
SelectNone
();
//
this.SelectNone();
}
//
}
break
;
//
break;
}
//
}
handler
=
this
.
Selected
;
handler
=
this
.
Selected
;
...
@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms
...
@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms
{
{
selection
=
this
.
FitRectangle
(
selection
);
selection
=
this
.
FitRectangle
(
selection
);
}
}
GraphicsPath
path
=
new
GraphicsPath
();
this
.
SelectionRegion
=
selection
;
Region
re
=
new
Region
();
path
.
AddRectangle
(
selection
);
this
.
SelectionRegion
=
path
;
}
}
}
}
}
}
...
...
ImageBox/ImageBox/ImageBoxSelectionMode.cs
查看文件 @
3589303
...
@@ -27,6 +27,6 @@
...
@@ -27,6 +27,6 @@
/// <summary>
/// <summary>
/// Zoom selection.
/// Zoom selection.
/// </summary>
/// </summary>
Zoom
Eclipse
,
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论