LabelingPosition.cs
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Model;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary.AutoScanAndLabel
{
public static class LabelingPosition
{
/// <summary>
/// 顺时针旋转
/// </summary>
/// <param name="lable">标签坐标</param>
/// <param name="center">中心点</param>
/// <param name="angle">旋转角度</param>
/// <returns></returns>
public static Point ClockwiseRotation(Point lable, Point center, double angle)
{
angle += 83;
double theta = angle * Math.PI / 180;
double x_new = (lable.X - center.X) * Math.Cos(theta) - (lable.Y - center.Y) * Math.Sin(theta) + center.X;
double y_new = (lable.X - center.X) * Math.Sin(theta) + (lable.Y - center.Y) * Math.Cos(theta) + center.Y;
LogNet.log.Info($"原坐标:{lable},中心点:{center},顺时针旋转:{angle}度,新坐标:x={x_new},y={y_new};");
return new Point((int)x_new, (int)y_new);
}
static void ImageSave(Bitmap bitmap)
{
string filepath = Application.StartupPath + "\\image\\Labeling\\";
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
else if (Directory.GetFiles(filepath).Length > 100)
{
try
{
Directory.Delete(filepath, true);
Directory.CreateDirectory(filepath);
}
catch (Exception)
{
LogNet.log.Info($"删除失败:{filepath}");
}
}
Bitmap bitmaps = (Bitmap)bitmap.Clone();
bitmaps.Save(filepath + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + DateTime.Now.Millisecond + ".jpg");
//LabelResult?.Invoke(new LabelResult() { Bitmap = (Bitmap)bitmap.Clone() });
//bitmap.Dispose();
}
}
}