Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
Line-Smart-Workstation
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit a0d26577
由
LN
编写于
2025-03-31 20:16:53 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
旋转问题修改
1 个父辈
94ce7964
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
35 行删除
TSA-V/frmBoard/FrmNImageViewer.cs
TSA-V/frmBoard/FrmNImageViewer.cs
查看文件 @
a0d2657
...
@@ -19,6 +19,9 @@ namespace TSA_V
...
@@ -19,6 +19,9 @@ namespace TSA_V
private
string
fileName
=
""
;
private
string
fileName
=
""
;
private
bool
update
=
false
;
private
bool
update
=
false
;
public
Image
lastImage
=
null
;
public
Image
lastImage
=
null
;
private
int
LastWidth
=
0
;
private
int
LastHeight
=
0
;
private
float
targetAngle
=
0
;
/// <summary>
/// <summary>
/// 选择图片的方式0=新增电路板。1=元器件图片
/// 选择图片的方式0=新增电路板。1=元器件图片
...
@@ -40,7 +43,10 @@ namespace TSA_V
...
@@ -40,7 +43,10 @@ namespace TSA_V
lastImage
=
myImage
;
lastImage
=
myImage
;
this
.
picViewer
.
Image
=
myImage
;
this
.
picViewer
.
Image
=
myImage
;
lastImage
=(
Image
)
myImage
.
Clone
();
LastWidth
=
lastImage
.
Width
;
LastHeight
=
lastImage
.
Height
;
targetAngle
=
0
;
img
.
Dispose
();
img
.
Dispose
();
btnOK
.
Focus
();
btnOK
.
Focus
();
}
}
...
@@ -108,40 +114,23 @@ namespace TSA_V
...
@@ -108,40 +114,23 @@ namespace TSA_V
// 旋转图片90度
// 旋转图片90度
RotateImage
(
v
);
RotateImage
(
v
);
}
}
//private void RotateImage(float angle)
//{
// update = true;
// Image originalImage = (Image)picViewer.Image.Clone();
// // 创建一个新的 Bitmap 用于存储旋转后的图片
// Bitmap bmp = new Bitmap(originalImage.Width, originalImage.Height);
// // 设置绘图的旋转角度和中心点
// Graphics g = Graphics.FromImage(bmp);
// g.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
// g.RotateTransform(angle);
// g.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
// // 绘制旋转后的图片
// g.DrawImage(originalImage, new Point(0, 0));
// g.Dispose();
// // 更新 PictureBox 中的图片
// picViewer.Image = bmp;
// // 更新旋转后的图片
// //rotatedImage = bmp;
//}
private
void
RotateImage
(
float
angle
)
private
void
RotateImage
(
float
angle
)
{
{
targetAngle
+=
angle
;
update
=
true
;
update
=
true
;
Image
originalImage
=
(
Image
)
picViewer
.
Image
.
Clone
();
//Image originalImage = (Image)picViewer.Image.Clone();
Image
originalImage
=
(
Image
)
lastImage
.
Clone
();
// 计算旋转后包含整个图像的最小矩形
// 计算旋转后包含整个图像的最小矩形
RectangleF
rotatedRect
=
new
RectangleF
(
0
,
0
,
originalImage
.
Width
,
originalImage
.
Height
);
RectangleF
rotatedRect
=
new
RectangleF
(
0
,
0
,
LastWidth
,
LastHeight
);
PointF
[]
points
=
new
PointF
[]
{
new
PointF
(
rotatedRect
.
Left
,
rotatedRect
.
Top
),
new
PointF
(
rotatedRect
.
Right
,
rotatedRect
.
Top
),
new
PointF
(
rotatedRect
.
Left
,
rotatedRect
.
Bottom
)
};
//RectangleF rotatedRect = new RectangleF(0, 0, originalImage.Width, originalImage.Height);
PointF
[]
points
=
new
PointF
[]
{
new
PointF
(
rotatedRect
.
Left
,
rotatedRect
.
Top
),
new
PointF
(
rotatedRect
.
Right
,
rotatedRect
.
Top
)
,
new
PointF
(
rotatedRect
.
Left
,
rotatedRect
.
Bottom
),
new
PointF
(
rotatedRect
.
Right
,
rotatedRect
.
Bottom
)
};
Matrix
matrix
=
new
Matrix
();
Matrix
matrix
=
new
Matrix
();
matrix
.
RotateAt
(
angle
,
new
PointF
(
rotatedRect
.
Width
/
2
,
rotatedRect
.
Height
/
2
));
float
pointA
=
targetAngle
%
360
;
matrix
.
RotateAt
(
pointA
,
new
PointF
(
rotatedRect
.
Width
/
2
,
rotatedRect
.
Height
/
2
));
matrix
.
TransformPoints
(
points
);
matrix
.
TransformPoints
(
points
);
rotatedRect
=
RectangleF
.
FromLTRB
(
points
.
Min
(
p
=>
p
.
X
),
points
.
Min
(
p
=>
p
.
Y
),
points
.
Max
(
p
=>
p
.
X
),
points
.
Max
(
p
=>
p
.
Y
));
rotatedRect
=
RectangleF
.
FromLTRB
(
points
.
Min
(
p
=>
p
.
X
),
points
.
Min
(
p
=>
p
.
Y
),
points
.
Max
(
p
=>
p
.
X
),
points
.
Max
(
p
=>
p
.
Y
));
...
@@ -151,7 +140,7 @@ namespace TSA_V
...
@@ -151,7 +140,7 @@ namespace TSA_V
// 设置绘图的旋转角度和中心点
// 设置绘图的旋转角度和中心点
Graphics
g
=
Graphics
.
FromImage
(
bmp
);
Graphics
g
=
Graphics
.
FromImage
(
bmp
);
g
.
TranslateTransform
(
rotatedRect
.
Width
/
2
,
rotatedRect
.
Height
/
2
);
g
.
TranslateTransform
(
rotatedRect
.
Width
/
2
,
rotatedRect
.
Height
/
2
);
g
.
RotateTransform
(
angle
);
g
.
RotateTransform
(
pointA
);
g
.
TranslateTransform
(-
originalImage
.
Width
/
2
,
-
originalImage
.
Height
/
2
);
g
.
TranslateTransform
(-
originalImage
.
Width
/
2
,
-
originalImage
.
Height
/
2
);
// 绘制旋转后的图片
// 绘制旋转后的图片
...
@@ -167,12 +156,6 @@ namespace TSA_V
...
@@ -167,12 +156,6 @@ namespace TSA_V
}
}
/// <summary>
/// 获取单通道的掩模图片
/// </summary>
/// <param name="img"></param>
/// <param name="path"></param>
/// <returns></returns>
public
Image
GetRoiMask
(
Image
img
,
GraphicsPath
path
)
public
Image
GetRoiMask
(
Image
img
,
GraphicsPath
path
)
{
{
if
(
path
!=
null
)
if
(
path
!=
null
)
...
@@ -244,6 +227,11 @@ namespace TSA_V
...
@@ -244,6 +227,11 @@ namespace TSA_V
Image
cutImage
=
CutImage
(
originalImage
,
path
,
true
);
Image
cutImage
=
CutImage
(
originalImage
,
path
,
true
);
picViewer
.
Image
=
cutImage
;
picViewer
.
Image
=
cutImage
;
picViewer
.
SelectionRegion
=
null
;
picViewer
.
SelectionRegion
=
null
;
lastImage
=
(
Image
)
cutImage
.
Clone
();
LastWidth
=
lastImage
.
Width
;
LastHeight
=
lastImage
.
Height
;
targetAngle
=
0
;
}
}
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论