-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFormMeters.cs
200 lines (150 loc) · 5.55 KB
/
FormMeters.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace USBCAN
{
public partial class FormMeters : Form
{
Image probe ;
VerticalProgressBar TempVp;
VerticalProgressBar OilVp;
int SpeedMeter = 0;
int MaxSpeed = 76;
int FuelMeter = 0;
int OilHeight = 0;
int MaxOilHeight = 120;
int tempriture = 0;
int Maxtemp = 120;
int Pressure = 0;
int MaxPressure =14;
public FormMeters()
{
InitializeComponent();
}
private void FormMeters_Load(object sender, EventArgs e)
{
Point LocatinPoint = new Point(450, 250);
int PointInterval = 25;
probe = Resource1.probe;
TempVp = new VerticalProgressBar();
OilVp = new VerticalProgressBar();
TempVp.Location = LocatinPoint;
TempVp.Width=20;
TempVp.Height = 100;
TempVp.Value = 10;
TempVp.Maximum = 500;
OilVp.Maximum = 500;
OilVp.Location = new Point(LocatinPoint.X+PointInterval, LocatinPoint.Y);
OilVp.Width = 20;
OilVp.Height = 100;
OilVp.Value = 30;
this.Controls.Add(TempVp);
this.Controls.Add(OilVp);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (Form1.htable.Contains(Form1.speed))
{
SpeedMeter = Convert.ToInt32(Form1.htable[Form1.speed]);
}
//
if (Form1.htable.Contains(Form1.OilHeight))
{
OilHeight = Convert.ToInt32(Form1.htable[Form1.OilHeight]);
}
if (Form1.htable.Contains(Form1.pressure))
{
Pressure = Convert.ToInt32(Form1.htable[Form1.pressure]);
}
if (Form1.htable.Contains(Form1.temp))
{
tempriture = Convert.ToInt32(Form1.htable[Form1.temp]);
}
// Pressure = Convert.ToInt32( Form1.htable[Form1.pressure]);
// tempriture =Convert.ToInt32( Form1.htable[Form1.temp]);
UpdateMeters();
}
/// <summary>
/// rotating the images
/// </summary>
/// <param name="filename"></param>
/// <param name="angle"></param>
/// <returns></returns>
public Image RotateImg(string filename, int angle)
{
return RotateImg(GetSourceImg(filename), angle);
}
public Image GetSourceImg(string filename)
{
Image img;
img = Bitmap.FromFile(filename);
return img;
}
public Image RotateImg(Image b, int angle)
{
angle = angle % 360;
//弧度转换
double radian = angle * Math.PI / 180.0;
double cos = Math.Cos(radian);
double sin = Math.Sin(radian);
//原图的宽和高
int w = b.Width;
int h = b.Height;
int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
//目标位图
Bitmap dsImage = new Bitmap(W, H);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//计算偏移量
Point Offset = new Point((W - w) / 2, (H - h) / 2);
//构造图像显示区域:让图像的中心与窗口的中心点一致
Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h);
Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
// Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);//original
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(360 - angle);
//恢复图像在水平和垂直方向的平移
g.TranslateTransform(-center.X, -center.Y);
g.DrawImage(b, rect);
//重至绘图的所有变换
g.ResetTransform();
g.Save();
g.Dispose();
//保存旋转后的图片
b.Dispose();
dsImage.Save("FocusPoint.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
return dsImage;
}
/// <summary>
/// 更新界面
/// </summary>
void UpdateMeters()
{
probe = Resource1.pro;
int SpeedAngle = (int)(SpeedMeter * (-3.55) - 180);
int TempAngle = (int)(tempriture * (-3.55) - 180);
int PressureAngle = (int)(Pressure * (-3.55) - 180);
//int OilHeightAngle=OilHeight/MaxOilHeight;
SpeedpictureBox.Image = RotateImg(probe, SpeedAngle);
PressurepictureBox.Image = RotateImg(Resource1.pro, PressureAngle);
OilHeightpicturebox.Image = RotateImg(Resource1.pro, TempAngle);
if (OilHeight < OilVp.Maximum)
{
OilVp.Value = OilHeight;
}
if (tempriture < TempVp.Maximum)
{
TempVp.Value = tempriture;
}
}
private void label5_Click(object sender, EventArgs e)
{
}
}
}