-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageShowingRegionAll.cs
More file actions
153 lines (119 loc) · 5.41 KB
/
Copy pathImageShowingRegionAll.cs
File metadata and controls
153 lines (119 loc) · 5.41 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace AutoPickingSys
{
class ImageShowingRegionAll
{
public Bitmap RegionShowingAll(Bitmap b, Color showColor, Dictionary<int, Characteristic> Characteristics,
Dictionary<int, Dictionary<int, Pixel>> DEdgeSortPoints, Dictionary<int, Pixel> Pixels)
{
Bitmap dstImage = (Bitmap)b.Clone();
int width = b.Width;
int height = b.Height;
Bitmap showingImage = new Bitmap(width, height);// (Bitmap)b.Clone();//
showingImage = (Bitmap)b.Clone();
//int buffer;
Dictionary<int, Characteristic> _characteristics = new Dictionary<int, Characteristic>();
_characteristics = Characteristics;
try
{
BitmapData srcData = b.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData shgData = showingImage.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
// 图像实际处理区域
unsafe
{
byte* src = (byte*)srcData.Scan0;
byte* shg = (byte*)shgData.Scan0;
byte* nsrc; byte* nshg;
int stride = srcData.Stride;
int offset = stride - width * 4;
byte* north; byte* south;
byte* west; byte* east;
nsrc = src;//保存左上角当前指针
nshg = shg;
for (int i = 0; i < width; i++)//
{
//纵向定位当前点指针
for (int j = 0; j < height; j++)//从上往下搜索
{
//dnum = 0;
src = nsrc + i * 4 + j * stride;
shg = nshg + i * 4 + j * stride;
shg[0] = src[0];
shg[1] = src[1];
shg[2] = src[2];
}
}
for (int k = 1; k <= _characteristics.Count(); k++)
{
Dictionary<int, Pixel> edgeSortPoints = new Dictionary<int, Pixel>();
int edgeX = 0; int edgeY = 0;
edgeSortPoints = DEdgeSortPoints[k];
edgeX = _characteristics[k].Centroid.X;
edgeY = _characteristics[k].Centroid.Y;
//for (int i = 1; i <= edgeSortPoints.Count(); i++)//画边缘;
//{
// shg = nshg + edgeSortPoints[i].X * 4 + edgeSortPoints[i].Y * stride;
// shg[0] = showColor.B;
// shg[1] = showColor.G;
// shg[2] = showColor.R;
//}
//for (int i = -1 * width / 150; i <= 1 * width / 150; i++)//画十字;
//{
// shg = nshg + (edgeX + i) * 4 + edgeY * stride;
// north = shg - stride;
// shg[0] = showColor.B;
// shg[1] = showColor.G;
// shg[2] = showColor.R;
// north[0] = showColor.B;
// north[1] = showColor.G;
// north[2] = showColor.R;
// shg = nshg + edgeX * 4 + (edgeY + i) * stride;
// west = shg + 4;
// shg[0] = showColor.B;
// shg[1] = showColor.G;
// shg[2] = showColor.R;
// west[0] = showColor.B;
// west[1] = showColor.G;
// west[2] = showColor.R;
//}
for (int i = -1; i <= 1; i++)//画十字;
{
shg = nshg + (edgeX + i) * 4 + edgeY * stride;
north = shg - stride;
shg[0] = showColor.B;
shg[1] = showColor.G;
shg[2] = showColor.R;
north[0] = showColor.B;
north[1] = showColor.G;
north[2] = showColor.R;
shg = nshg + edgeX * 4 + (edgeY + i) * stride;
west = shg + 4;
shg[0] = showColor.B;
shg[1] = showColor.G;
shg[2] = showColor.R;
west[0] = showColor.B;
west[1] = showColor.G;
west[2] = showColor.R;
}
}
}
b.UnlockBits(srcData);
showingImage.UnlockBits(shgData);
b.Dispose();
dstImage = showingImage;
}
catch (Exception ex)
{
GC.Collect();
}
return dstImage;
}
}
}