BioImager  3.9.1
A .NET microscopy imaging library. Supports various microscopes by using imported libraries & GUI automation. Supported libraries include PriorĀ® & ZeissĀ® & all devices supported by Micromanager 2.0 and python-microscope.
Loading...
Searching...
No Matches
BioImager.Graphics.Graphics Class Reference
Inheritance diagram for BioImager.Graphics.Graphics:

Public Member Functions

void DrawLine (int x, int y, int x2, int y2)
 
void DrawLine (PointF p, PointF p2)
 
void FillRectangle (Rectangle r, ColorS col)
 
void FillRectangle (RectangleF r, ColorS col)
 
void DrawRectangle (Rectangle r)
 
void DrawRectangle (RectangleF r)
 
void DrawEllipse (Rectangle r)
 
void DrawEllipse (RectangleF r)
 
void FillEllipse (float xx, float yy, int w, int h, ColorS c)
 
void FillEllipse (RectangleF r, ColorS c)
 
void FillEllipse (Rectangle r, ColorS c)
 
void FillPolygon (PointF[] pfs, Rectangle r)
 
void FillPolygon (PointF[] pfs, RectangleF r)
 
bool PointInPolygon (int x, int y)
 
void FillPolygon (PointF[] pfs, Rectangle r, ColorS c)
 
void FillPolygon (PointF[] pfs, RectangleF r, ColorS c)
 
void DrawScanline (int x, int x2, int line, ColorS col)
 
void Dispose ()
 

Static Public Member Functions

static Graphics FromImage (Bitmap b)
 

Public Attributes

Bitmap buf
 
Pen pen
 

Detailed Description

Definition at line 32 of file Graphics.cs.

Member Function Documentation

◆ Dispose()

void BioImager.Graphics.Graphics.Dispose ( )

Definition at line 286 of file Graphics.cs.

287 {
288 pen.Dispose();
289 }

◆ DrawEllipse() [1/2]

void BioImager.Graphics.Graphics.DrawEllipse ( Rectangle  r)

Definition at line 158 of file Graphics.cs.

159 {
160 if (r.Width == 1 && r.Height == 1)
161 buf.SetPixel(r.X, r.Y, pen.color);
162 double radiusx = r.Width / 2;
163 double radiusy = r.Height / 2;
164 int x, y;
165 for (double a = 0.0; a < 360.0; a += 0.1)
166 {
167 double angle = a * System.Math.PI / 180;
168 for (int i = 0; i < pen.width; i++)
169 {
170 x = (int)(radiusx * System.Math.Cos(angle) + radiusx + r.X);
171 y = (int)(radiusy * System.Math.Sin(angle) + radiusy + r.Y);
172 buf.SetPixel(x + i, y + i, pen.color);
173 }
174 }
175 }

◆ DrawEllipse() [2/2]

void BioImager.Graphics.Graphics.DrawEllipse ( RectangleF  r)

Definition at line 176 of file Graphics.cs.

177 {
178 DrawEllipse(new Rectangle((int)Math.Ceiling(r.X), (int)Math.Ceiling(r.Y), (int)Math.Ceiling(r.Width), (int)Math.Ceiling(r.Height)));
179 }

◆ DrawLine() [1/2]

void BioImager.Graphics.Graphics.DrawLine ( int  x,
int  y,
int  x2,
int  y2 
)

Definition at line 44 of file Graphics.cs.

45 {
46 //Bresenham's algorithm for line drawing.
47 int w = x2 - x;
48 int h = y2 - y;
49 int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
50 if (w < 0) dx1 = -1; else if (w > 0) dx1 = 1;
51 if (h < 0) dy1 = -1; else if (h > 0) dy1 = 1;
52 if (w < 0) dx2 = -1; else if (w > 0) dx2 = 1;
53 int longest = Math.Abs(w);
54 int shortest = Math.Abs(h);
55 if (!(longest > shortest))
56 {
57 longest = Math.Abs(h);
58 shortest = Math.Abs(w);
59 if (h < 0) dy2 = -1; else if (h > 0) dy2 = 1;
60 dx2 = 0;
61 }
62 int numerator = longest >> 1;
63 for (int i = 0; i <= longest; i++)
64 {
65 FillEllipse(x, y, pen.width, pen.width, pen.color);
66 numerator += shortest;
67 if (!(numerator < longest))
68 {
69 numerator -= longest;
70 x += dx1;
71 y += dy1;
72 }
73 else
74 {
75 x += dx2;
76 y += dy2;
77 }
78 }
79 }

◆ DrawLine() [2/2]

void BioImager.Graphics.Graphics.DrawLine ( PointF  p,
PointF  p2 
)

Definition at line 116 of file Graphics.cs.

117 {
118 DrawLine((int)p.X, (int)p.Y, (int)p2.X, (int)p2.Y);
119 }

◆ DrawRectangle() [1/2]

void BioImager.Graphics.Graphics.DrawRectangle ( Rectangle  r)

Definition at line 134 of file Graphics.cs.

135 {
136 for (int x = r.X; x < r.Width + r.X; x++)
137 {
138 for (int i = 0; i < pen.width; i++)
139 {
140 buf.SetPixel(x + i, r.Y, pen.color);
141 buf.SetPixel(x + i, r.Y + r.Height, pen.color);
142 }
143 }
144 for (int y = r.Y; y < r.Height + r.Y; y++)
145 {
146 for (int i = 0; i < pen.width; i++)
147 {
148 buf.SetPixel(r.X, y + i, pen.color);
149 buf.SetPixel(r.X + r.Width, y + i, pen.color);
150 }
151 }
152 }

◆ DrawRectangle() [2/2]

void BioImager.Graphics.Graphics.DrawRectangle ( RectangleF  r)

Definition at line 153 of file Graphics.cs.

154 {
155 DrawRectangle(new Rectangle((int)Math.Ceiling(r.X), (int)Math.Ceiling(r.Y), (int)Math.Ceiling(r.Width), (int)Math.Ceiling(r.Height)));
156 }

◆ DrawScanline()

void BioImager.Graphics.Graphics.DrawScanline ( int  x,
int  x2,
int  line,
ColorS  col 
)

Definition at line 279 of file Graphics.cs.

280 {
281 for (int xx = x; xx < x2; xx++)
282 {
283 buf.SetPixel(xx, line, col);
284 }
285 }

◆ FillEllipse() [1/3]

void BioImager.Graphics.Graphics.FillEllipse ( float  xx,
float  yy,
int  w,
int  h,
ColorS  c 
)

Definition at line 180 of file Graphics.cs.

181 {
182 if (w <= 1 && w <= 1)
183 {
184 buf.SetPixel((int)xx, (int)yy, c);
185 return;
186 }
187 double radiusx = w / 2;
188 double radiusy = h / 2;
189 int x, y;
190 for (double a = 90; a < 270; a += 0.1)
191 {
192 double angle = a * System.Math.PI / 180;
193 x = (int)(radiusx * System.Math.Cos(angle) + radiusx + xx);
194 y = (int)(radiusy * System.Math.Sin(angle) + radiusy + yy);
195 double angle2 = (a + 180) * System.Math.PI / 180;
196 int x2 = (int)(radiusx * System.Math.Cos(angle2) + radiusx + xx);
197 DrawScanline(x, x2, y, c);
198 }
199 }

◆ FillEllipse() [2/3]

void BioImager.Graphics.Graphics.FillEllipse ( Rectangle  r,
ColorS  c 
)

Definition at line 204 of file Graphics.cs.

205 {
206 FillEllipse(r.X, r.Y, r.Width, r.Height, c);
207 }

◆ FillEllipse() [3/3]

void BioImager.Graphics.Graphics.FillEllipse ( RectangleF  r,
ColorS  c 
)

Definition at line 200 of file Graphics.cs.

201 {
202 FillEllipse(new Rectangle((int)Math.Ceiling(r.X), (int)Math.Ceiling(r.Y), (int)Math.Ceiling(r.Width), (int)Math.Ceiling(r.Height)), c);
203 }

◆ FillPolygon() [1/4]

void BioImager.Graphics.Graphics.FillPolygon ( PointF[]  pfs,
Rectangle  r 
)

Definition at line 208 of file Graphics.cs.

209 {
210 //We will use the flood fill algorithm to fill the polygon.
211 //First we need to create a new Buffer incase the current Buffer contains filled pixels that could prevent flood fill from filling the whole area.
212 Bitmap bf = buf.CopyInfo();
213 bf.Bytes = new byte[buf.Bytes.Length];
214
215 DrawPolygon(pfs, bf, pen.color);
216
217 filler = new QueueLinearFloodFiller(filler);
218 filler.FillColor = pen.color;
219 filler.Tolerance = new ColorS(0, 0, 0);
220 filler.Bitmap = bf;
221 //Next we need to find a point inside the polygon from where to start the flood fill.
222 //We use the center points x-line till we find a point inside.
223 Point p = new Point(r.X + (r.Width / 2), r.Y + (r.Height / 2));
224 Point? pp = null;
225 polygon = pfs;
226 for (int x = r.X; x < r.Width + r.X; x++)
227 {
228 if (PointInPolygon(x, (int)p.Y))
229 {
230 pp = new Point(x, p.Y);
231 break;
232 }
233 }
234 filler.FloodFill(pp.Value);
235 //Now that we have a filled shape we draw it onto the original bitmap
236 for (int x = 0; x < bf.SizeX; x++)
237 {
238 for (int y = 0; y < bf.SizeY; y++)
239 {
240 if (bf.GetPixel(x, y) == pen.color)
241 {
242 buf.SetPixel(x, y, pen.color);
243 }
244 }
245 }
246 bf.Dispose();
247 }

◆ FillPolygon() [2/4]

void BioImager.Graphics.Graphics.FillPolygon ( PointF[]  pfs,
Rectangle  r,
ColorS  c 
)

Definition at line 261 of file Graphics.cs.

262 {
263 pen.color = c;
264 FillPolygon(pfs, r);
265 }

◆ FillPolygon() [3/4]

void BioImager.Graphics.Graphics.FillPolygon ( PointF[]  pfs,
RectangleF  r 
)

Definition at line 248 of file Graphics.cs.

249 {
250 FillPolygon(pfs, new Rectangle((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height));
251 }

◆ FillPolygon() [4/4]

void BioImager.Graphics.Graphics.FillPolygon ( PointF[]  pfs,
RectangleF  r,
ColorS  c 
)

Definition at line 266 of file Graphics.cs.

267 {
268 pen.color = c;
269 FillPolygon(pfs, r);
270 }

◆ FillRectangle() [1/2]

void BioImager.Graphics.Graphics.FillRectangle ( Rectangle  r,
ColorS  col 
)

Definition at line 120 of file Graphics.cs.

121 {
122 for (int x = r.X; x < r.Width + r.X; x++)
123 {
124 for (int y = r.Y; y < r.Height + r.Y; y++)
125 {
126 buf.SetPixel(x, y, col);
127 }
128 }
129 }

◆ FillRectangle() [2/2]

void BioImager.Graphics.Graphics.FillRectangle ( RectangleF  r,
ColorS  col 
)

Definition at line 130 of file Graphics.cs.

131 {
132 FillRectangle(new Rectangle((int)Math.Ceiling(r.X), (int)Math.Ceiling(r.Y), (int)Math.Ceiling(r.Width), (int)Math.Ceiling(r.Height)), col);
133 }

◆ FromImage()

static Graphics BioImager.Graphics.Graphics.FromImage ( Bitmap  b)
static

Definition at line 37 of file Graphics.cs.

38 {
39 Graphics g = new Graphics();
40 g.buf = b;
41 g.pen = new Pen(new ColorS(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue), 1, b.BitsPerPixel);
42 return g;
43 }

◆ PointInPolygon()

bool BioImager.Graphics.Graphics.PointInPolygon ( int  x,
int  y 
)

Definition at line 253 of file Graphics.cs.

254 {
255 int j = polygon.Length - 1;
256 bool c = false;
257 for (int i = 0; i < polygon.Length; j = i++) c ^= polygon[i].Y > y ^ polygon[j].Y > y && x < (polygon[j].X - polygon[i].X) * (y - polygon[i].Y) / (polygon[j].Y - polygon[i].Y) + polygon[i].X;
258 return c;
259 }

Member Data Documentation

◆ buf

Bitmap BioImager.Graphics.Graphics.buf

Definition at line 34 of file Graphics.cs.

◆ pen

Pen BioImager.Graphics.Graphics.pen

Definition at line 35 of file Graphics.cs.


The documentation for this class was generated from the following file: