-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.cs
656 lines (628 loc) · 31.7 KB
/
Tools.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Paint
{
// 工具类型
public enum ToolsType
{
裁剪,
橡皮,
取色,
铅笔,
喷枪,
直线,
矩形,
椭圆,
选定,
填充,
放大镜,
刷子,
文字,
曲线,
多边形,
圆角矩形
}
// 鼠标状态类型
public enum MouseStateType
{
MouseDown,
MouseMove,
MouseUp
}
//工具型号
public enum ToolSize
{
Size_1,
Size_2,
Size_3,
Size_4,
Size_5,
Size_6,
Size_7,
Size_8,
Size_9,
Size_10,
Size_11,
Size_12
}
class Tools
{
public static ToolSize m_ToolSize = ToolSize.Size_1;
public static bool m_TempImageUsed = false;
public static MouseStateType m_MouseState = MouseStateType.MouseUp;
public static Point m_PreviousPoint = Point.Empty;
public static List<Point> m_PointList = new List<Point>();
private static Random m_Random = new Random(); //随机数发生器
public static void Init()
{
m_ToolSize = ToolSize.Size_1;
m_TempImageUsed = false;
m_MouseState = MouseStateType.MouseUp;
m_PreviousPoint = Point.Empty;
m_PointList.Clear();
}
/*
static void 裁剪()
{
switch()
{
}
}
*/
public static void 橡皮(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap)
{
int iSize = 2 * (int)m_ToolSize + 1;
switch (mouseType)
{
case MouseStateType.MouseDown:
{
Graphics.FromImage(sourceBitmap).FillRectangle(new SolidBrush(colorType), targetPoint.X - iSize, targetPoint.Y - iSize, iSize * 2, iSize * 2);
m_MouseState = MouseStateType.MouseDown;
break;
}
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Graphics.FromImage(sourceBitmap).FillRectangle(new SolidBrush(colorType), targetPoint.X - iSize, targetPoint.Y - iSize, iSize * 2, iSize * 2);
}
break;
case MouseStateType.MouseUp:
m_MouseState = MouseStateType.MouseUp;
break;
}
}
public static Color 取色(MouseStateType mouseType, Point targetPoint, ref Bitmap sourceBitmap)
{
Color returnColor = Color.Empty;
switch (mouseType)
{
case MouseStateType.MouseDown:
if (sourceBitmap.Width > targetPoint.X && 0 < targetPoint.X && sourceBitmap.Height > targetPoint.Y && 0 < targetPoint.Y)
{
returnColor = sourceBitmap.GetPixel(targetPoint.X, targetPoint.Y);
}
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState && sourceBitmap.Width > targetPoint.X && 0 < targetPoint.X && sourceBitmap.Height > targetPoint.Y && 0 < targetPoint.Y)
{
returnColor = sourceBitmap.GetPixel(targetPoint.X, targetPoint.Y);
}
break;
case MouseStateType.MouseUp:
if (sourceBitmap.Width > targetPoint.X && 0 < targetPoint.X && sourceBitmap.Height > targetPoint.Y && 0 < targetPoint.Y)
{
returnColor = sourceBitmap.GetPixel(targetPoint.X, targetPoint.Y);
}
m_MouseState = MouseStateType.MouseUp;
break;
}
return returnColor;
}
public static void 铅笔(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Graphics.FromImage(sourceBitmap).DrawLine(new Pen(colorType, 1), m_PreviousPoint, targetPoint);
m_PreviousPoint = targetPoint;
}
break;
case MouseStateType.MouseUp:
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
public static void 喷枪(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
{
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
}
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
int iSize = 5 * ((int)m_ToolSize + 1);
for (int i = 0; i < 25; ++i)
{
int x = 0, y = 0;
do
{
x = m_Random.Next(-iSize, iSize);
y = m_Random.Next(-iSize, iSize);
}
while (x * x + y * y > iSize * iSize);
int oriX = Tools.m_PreviousPoint.X + x, oriY = Tools.m_PreviousPoint.Y + y;
if (0 < oriX && oriX < sourceBitmap.Width && 0 < oriY && oriY < sourceBitmap.Height)
{
sourceBitmap.SetPixel(Tools.m_PreviousPoint.X + x, Tools.m_PreviousPoint.Y + y, colorType);
}
}
}
break;
case MouseStateType.MouseUp:
m_MouseState = MouseStateType.MouseUp;
break;
}
}
public static void 直线(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref Bitmap temporyImage)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_TempImageUsed = true;
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Graphics.FromImage(temporyImage).Clear(Color.Empty);
Graphics.FromImage(temporyImage).DrawLine(new Pen(colorType, (int)m_ToolSize), m_PreviousPoint, targetPoint);
}
break;
case MouseStateType.MouseUp:
{
m_TempImageUsed = false;
Graphics.FromImage(sourceBitmap).DrawLine(new Pen(colorType, (int)m_ToolSize), m_PreviousPoint, targetPoint);
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
}
public static void 矩形(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref Bitmap temporyImage)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_TempImageUsed = true;
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Point staticPoint = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
targetPoint.X = Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X);
targetPoint.Y = Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y);
Graphics.FromImage(temporyImage).Clear(Color.Empty);
switch (m_ToolSize)
{
case ToolSize.Size_1:
Graphics.FromImage(temporyImage).DrawRectangle(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_2:
Graphics.FromImage(temporyImage).FillRectangle(Brushes.White, staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
Graphics.FromImage(temporyImage).DrawRectangle(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_3:
Graphics.FromImage(temporyImage).FillRectangle(new SolidBrush(colorType), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
}
}
break;
case MouseStateType.MouseUp:
{
m_TempImageUsed = false;
Point staticPoint = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
targetPoint.X = Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X);
targetPoint.Y = Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y);
switch (m_ToolSize)
{
case ToolSize.Size_1:
Graphics.FromImage(sourceBitmap).DrawRectangle(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_2:
Graphics.FromImage(sourceBitmap).FillRectangle(Brushes.White, staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
Graphics.FromImage(sourceBitmap).DrawRectangle(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_3:
Graphics.FromImage(sourceBitmap).FillRectangle(new SolidBrush(colorType), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
}
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
}
public static void 椭圆(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref Bitmap temporyImage)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_TempImageUsed = true;
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Point staticPoint = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
targetPoint.X = Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X);
targetPoint.Y = Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y);
Graphics.FromImage(temporyImage).Clear(Color.Empty);
switch (m_ToolSize)
{
case ToolSize.Size_1:
Graphics.FromImage(temporyImage).DrawEllipse(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_2:
Graphics.FromImage(temporyImage).FillEllipse(Brushes.White, staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
Graphics.FromImage(temporyImage).DrawEllipse(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_3:
Graphics.FromImage(temporyImage).FillEllipse(new SolidBrush(colorType), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
}
}
break;
case MouseStateType.MouseUp:
{
m_TempImageUsed = false;
Point staticPoint = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
targetPoint.X = Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X);
targetPoint.Y = Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y);
switch (m_ToolSize)
{
case ToolSize.Size_1:
Graphics.FromImage(sourceBitmap).DrawEllipse(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_2:
Graphics.FromImage(sourceBitmap).FillEllipse(Brushes.White, staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
Graphics.FromImage(sourceBitmap).DrawEllipse(new Pen(colorType, 1), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
case ToolSize.Size_3:
Graphics.FromImage(sourceBitmap).FillEllipse(new SolidBrush(colorType), staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y);
break;
}
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
}
/*
class 选定
{
}
class 填充
{
}
class 放大镜
{
}
*/
public static void 刷子(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref Bitmap temporyImage)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_TempImageUsed = true;
m_PreviousPoint = targetPoint;
m_PointList.Add(m_PreviousPoint);
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
m_PreviousPoint = targetPoint;
m_PointList.Add(m_PreviousPoint);
DrawPolygon(Graphics.FromImage(temporyImage), colorType, false, false, false, 10);
m_TempImageUsed = true;
}
break;
case MouseStateType.MouseUp:
m_TempImageUsed = false;
if (1 <= m_PointList.Count)
{
m_PointList.Add(targetPoint);
DrawPolygon(Graphics.FromImage(sourceBitmap), colorType, false, false, false,10);
}
m_PointList.Clear();
Graphics.FromImage(temporyImage).Clear(Color.Empty);
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
public static void 文字(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref System.Windows.Forms.TextBox alphaTextBox)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_PreviousPoint = targetPoint;
if (alphaTextBox.Visible)
{
for (int i = 0; i < alphaTextBox.Lines.Length; ++ i)
{
Point newLocation = new Point(alphaTextBox.Location.X, alphaTextBox.Location.Y + i * (alphaTextBox.Font.Height - 5));
Graphics.FromImage(sourceBitmap).DrawString(alphaTextBox.Lines[i], alphaTextBox.Font, new SolidBrush(Color.FromArgb(255, alphaTextBox.ForeColor)), newLocation);
}
//Graphics.FromImage(sourceBitmap).DrawString(alphaTextBox.Text, alphaTextBox.Font, new SolidBrush(Color.FromArgb(255, alphaTextBox.ForeColor)), new Point(alphaTextBox.Location.X, alphaTextBox.Location.Y));
alphaTextBox.Text = "";
alphaTextBox.Visible = false;
}
else
{
alphaTextBox.Location = Tools.m_PreviousPoint;
alphaTextBox.ForeColor = colorType;
alphaTextBox.Font = new Font(alphaTextBox.Font.FontFamily,22, alphaTextBox.Font.Style);
alphaTextBox.Visible = true;
}
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState && alphaTextBox.Visible)
{
alphaTextBox.Location = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
alphaTextBox.Size = new Size(Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X), Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y));
}
break;
case MouseStateType.MouseUp:
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
//real参数:为了在切换工具后及时将临时曲线绘制并销毁点数组
public static void 曲线(MouseStateType mouseType, Point targetPoint, Color colorType, Bitmap sourceBitmap, Bitmap temporyImage, bool real = false)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_TempImageUsed = true;
if (0 == m_PointList.Count)
{
m_PointList.Add(targetPoint);
}
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Graphics.FromImage(temporyImage).Clear(Color.Empty);
switch (m_PointList.Count)
{
case 1:
Graphics.FromImage(temporyImage).DrawLine(new Pen(colorType, (int)m_ToolSize), m_PointList[0], targetPoint);
break;
case 2:
Graphics.FromImage(temporyImage).DrawBezier(new Pen(colorType, (int)m_ToolSize), m_PointList[1], targetPoint, m_PointList[0], m_PointList[0]);
break;
case 3:
Graphics.FromImage(temporyImage).DrawBezier(new Pen(colorType, (int)m_ToolSize), m_PointList[1], targetPoint, m_PointList[2], m_PointList[0]);
break;
}
}
break;
case MouseStateType.MouseUp:
{
if (!real)
{
if (m_PointList.Count < 3)
{
m_PointList.Add(targetPoint);
}
else
{
m_TempImageUsed = false;
Graphics.FromImage(sourceBitmap).DrawBezier(new Pen(colorType, (int)m_ToolSize), m_PointList[1], targetPoint, m_PointList[2], m_PointList[0]);
m_PointList.Clear();
}
}
else
{
m_TempImageUsed = false;
switch (m_PointList.Count)
{
case 1:
break;
case 2:
Graphics.FromImage(sourceBitmap).DrawLine(new Pen(colorType, (int)m_ToolSize), m_PointList[0], m_PointList[1]);
break;
case 3:
Graphics.FromImage(sourceBitmap).DrawBezier(new Pen(colorType, (int)m_ToolSize), m_PointList[1], m_PointList[2], m_PointList[0], m_PointList[0]);
break;
}
m_PointList.Clear();
}
m_MouseState = MouseStateType.MouseUp;
break;
}
}
}
public static void 多边形(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref Bitmap temporyImage)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
if (1 <= m_PointList.Count)
{
Graphics.FromImage(temporyImage).DrawLine(new Pen(colorType, 1), targetPoint, m_PointList[m_PointList.Count - 1]);
}
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
if (!m_TempImageUsed)
{
m_TempImageUsed = true;
if (0 == Tools.m_PointList.Count)
{
Tools.m_PointList.Add(m_PreviousPoint);
}
}
Graphics.FromImage(temporyImage).Clear(Color.Empty);
if (1 < m_PointList.Count)
{
Graphics.FromImage(temporyImage).DrawLines(new Pen(colorType, 1), m_PointList.ToArray());
}
Graphics.FromImage(temporyImage).DrawLine(new Pen(colorType, 1), targetPoint, m_PointList[m_PointList.Count - 1]);
}
break;
case MouseStateType.MouseUp:
if (1 <= m_PointList.Count)
{
Tools.m_PointList.Add(targetPoint);
Graphics.FromImage(temporyImage).DrawLines(new Pen(colorType, 1), m_PointList.ToArray());
}
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
public static void 圆角矩形(MouseStateType mouseType, Point targetPoint, Color colorType, ref Bitmap sourceBitmap, ref Bitmap temporyImage)
{
switch (mouseType)
{
case MouseStateType.MouseDown:
m_TempImageUsed = true;
m_PreviousPoint = targetPoint;
m_MouseState = MouseStateType.MouseDown;
break;
case MouseStateType.MouseMove:
if (MouseStateType.MouseDown == m_MouseState)
{
Point staticPoint = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
targetPoint.X = Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X);
targetPoint.Y = Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y);
Graphics.FromImage(temporyImage).Clear(Color.Empty);
switch (m_ToolSize)
{
case ToolSize.Size_1:
DrawRoundRectangle(Graphics.FromImage(temporyImage), colorType, new Rectangle(staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y), 8);
break;
case ToolSize.Size_2:
DrawRoundRectangle(Graphics.FromImage(temporyImage), colorType, new Rectangle(staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y), 8, true, true);
break;
case ToolSize.Size_3:
DrawRoundRectangle(Graphics.FromImage(temporyImage), colorType, new Rectangle(staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y), 8, true, false);
break;
}
}
break;
case MouseStateType.MouseUp:
{
m_TempImageUsed = false;
Point staticPoint = new Point((Tools.m_PreviousPoint.X < targetPoint.X) ? Tools.m_PreviousPoint.X : targetPoint.X, (Tools.m_PreviousPoint.Y < targetPoint.Y) ? Tools.m_PreviousPoint.Y : targetPoint.Y);
targetPoint.X = Math.Abs(targetPoint.X - Tools.m_PreviousPoint.X);
targetPoint.Y = Math.Abs(targetPoint.Y - Tools.m_PreviousPoint.Y);
switch (m_ToolSize)
{
case ToolSize.Size_1:
DrawRoundRectangle(Graphics.FromImage(sourceBitmap), colorType, new Rectangle(staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y), 8);
break;
case ToolSize.Size_2:
DrawRoundRectangle(Graphics.FromImage(sourceBitmap), colorType, new Rectangle(staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y), 8, true, true);
break;
case ToolSize.Size_3:
DrawRoundRectangle(Graphics.FromImage(sourceBitmap), colorType, new Rectangle(staticPoint.X, staticPoint.Y, targetPoint.X, targetPoint.Y), 8, true, false);
break;
}
m_PreviousPoint = Point.Empty;
m_MouseState = MouseStateType.MouseUp;
break;
}
}
}
//绘制多边形
public static void DrawPolygon(Graphics g, Color color, bool bISolid = false, bool bIsWhiteSolid = false, bool bIsCloseFigure = true,int iSize = 1)
{
m_TempImageUsed = false;
GraphicsPath tempGraphicsPath = new GraphicsPath();
if (1 < m_PointList.Count)
{
tempGraphicsPath.AddLines(Tools.m_PointList.ToArray());
if (bIsCloseFigure)
{
tempGraphicsPath.CloseFigure();
}
if (bISolid)
{
if (!bIsWhiteSolid)
{
g.FillPath(new SolidBrush(color), tempGraphicsPath);
return;
}
g.FillPath(Brushes.White, tempGraphicsPath);
}
g.DrawPath(new Pen(color, iSize), tempGraphicsPath);
}
}
//绘制圆角矩形
public static void DrawRoundRectangle(Graphics g, Color color, Rectangle rect, int cornerRadius, bool bISolid = false, bool bIsWhiteSolid = false)
{
GraphicsPath tempGraphicsPath = CreateRoundedRectanglePath(rect, cornerRadius);
if (bISolid)
{
if (!bIsWhiteSolid)
{
g.FillPath(new SolidBrush(color), tempGraphicsPath);
return;
}
g.FillPath(Brushes.White, tempGraphicsPath);
}
g.DrawPath(new Pen(color), tempGraphicsPath);
}
//生成圆角矩形区域
internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, float cornerRadius)
{
GraphicsPath roundedRect = new GraphicsPath();
int iLen = rect.Height;
if (rect.Height > rect.Width)
{
iLen = rect.Width;
}
if (iLen < 2 * cornerRadius)
{
roundedRect.AddEllipse(rect);
return roundedRect;
}
roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
roundedRect.CloseFigure();
return roundedRect;
}
}
}