Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
AccAOI
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 538dd72a
由
SK
编写于
2019-06-17 15:17:49 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
ImageBox
1 个父辈
fe860d03
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
56 行增加
和
39 行删除
AccAOI/imageBoxEx/ImageBoxEx.cs
ImageBox/ImageBox.cs
ImageBox/ImageBox/ImageBoxSelectionMode.cs
AccAOI/imageBoxEx/ImageBoxEx.cs
查看文件 @
538dd72
此文件的差异被折叠,
点击展开。
ImageBox/ImageBox.cs
查看文件 @
538dd72
...
...
@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms
[
DefaultProperty
(
"Image"
)]
[
ToolboxBitmap
(
typeof
(
ImageBox
),
"ImageBox.bmp"
)]
[
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
...
...
@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms
private
ImageBoxSelectionMode
_selectionMode
;
private
RectangleF
_selectionRegion
;
private
GraphicsPath
_selectionRegion
=
new
GraphicsPath
()
;
private
bool
_shortcutsEnabled
;
...
...
@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms
this
.
DrawPixelGrid
(
e
.
Graphics
);
}
// draw the selection
if
(
this
.
SelectionRegion
!=
Rectangle
.
Empty
)
if
(
this
.
SelectionRegion
.
PointCount
>
0
)
{
this
.
DrawSelection
(
e
);
}
...
...
@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms
/// </value>
[
Browsable
(
false
)]
[
DesignerSerializationVisibility
(
DesignerSerializationVisibility
.
Hidden
)]
public
virtual
RectangleF
SelectionRegion
public
virtual
GraphicsPath
SelectionRegion
{
get
{
return
_selectionRegion
;
}
set
...
...
@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms
result
=
null
;
if
(!
this
.
SelectionRegion
.
IsEmpty
)
var
bounds
=
this
.
SelectionRegion
.
GetBounds
();
if
(
this
.
SelectionRegion
.
PointCount
>
0
)
{
Rectangle
rect
;
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
)
if
(
bounds
.
Width
>
0
&&
bounds
.
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
))
{
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
}
/// <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
/// </summary>
public
virtual
void
SelectNone
()
{
this
.
SelectionRegion
=
RectangleF
.
Empty
;
this
.
SelectionRegion
=
new
GraphicsPath
()
;
}
/// <summary>
...
...
@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms
/// </param>
protected
virtual
void
DrawSelection
(
PaintEventArgs
e
)
{
RectangleF
rect
;
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
)))
{
e
.
Graphics
.
FillRectangle
(
brush
,
rect
);
e
.
Graphics
.
FillPath
(
brush
,
newPath
);
}
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
();
...
...
@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms
{
EventHandler
<
EventArgs
>
handler
;
switch
(
this
.
SelectionMode
)
{
case
ImageBoxSelectionMode
.
Zoom
:
if
(
this
.
SelectionRegion
.
Width
>
SelectionDeadZone
&&
this
.
SelectionRegion
.
Height
>
SelectionDeadZone
)
{
this
.
ZoomToRegion
(
this
.
SelectionRegion
);
this
.
SelectNone
();
}
break
;
}
//
switch (this.SelectionMode)
//
{
//
case ImageBoxSelectionMode.Zoom:
//
if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
//
{
//
this.ZoomToRegion(this.SelectionRegion);
//
this.SelectNone();
//
}
//
break;
//
}
handler
=
this
.
Selected
;
...
...
@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms
{
selection
=
this
.
FitRectangle
(
selection
);
}
this
.
SelectionRegion
=
selection
;
GraphicsPath
path
=
new
GraphicsPath
();
Region
re
=
new
Region
();
path
.
AddRectangle
(
selection
);
this
.
SelectionRegion
=
path
;
}
}
}
...
...
ImageBox/ImageBox/ImageBoxSelectionMode.cs
查看文件 @
538dd72
...
...
@@ -27,6 +27,6 @@
/// <summary>
/// Zoom selection.
/// </summary>
Zoom
Eclipse
,
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论