4 public struct Pen : IDisposable
35 g.pen =
new Pen(
new ColorS(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue), 1, b.BitsPerPixel);
38 public void DrawLine(
int x,
int y,
int x2,
int y2)
43 int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
44 if (w < 0) dx1 = -1;
else if (w > 0) dx1 = 1;
45 if (h < 0) dy1 = -1;
else if (h > 0) dy1 = 1;
46 if (w < 0) dx2 = -1;
else if (w > 0) dx2 = 1;
47 int longest = Math.Abs(w);
48 int shortest = Math.Abs(h);
49 if (!(longest > shortest))
51 longest = Math.Abs(h);
52 shortest = Math.Abs(w);
53 if (h < 0) dy2 = -1;
else if (h > 0) dy2 = 1;
56 int numerator = longest >> 1;
57 for (
int i = 0; i <= longest; i++)
60 numerator += shortest;
61 if (!(numerator < longest))
74 private void DrawLine(
int x,
int y,
int x2,
int y2, Bitmap bf, ColorS c)
79 int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
80 if (w < 0) dx1 = -1;
else if (w > 0) dx1 = 1;
81 if (h < 0) dy1 = -1;
else if (h > 0) dy1 = 1;
82 if (w < 0) dx2 = -1;
else if (w > 0) dx2 = 1;
83 int longest = Math.Abs(w);
84 int shortest = Math.Abs(h);
85 if (!(longest > shortest))
87 longest = Math.Abs(h);
88 shortest = Math.Abs(w);
89 if (h < 0) dy2 = -1;
else if (h > 0) dy2 = 1;
92 int numerator = longest >> 1;
93 for (
int i = 0; i <= longest; i++)
96 numerator += shortest;
97 if (!(numerator < longest))
112 DrawLine((
int)p.X, (
int)p.Y, (
int)p2.X, (
int)p2.Y);
116 for (
int x = r.X; x < r.Width + r.X; x++)
118 for (
int y = r.Y; y < r.Height + r.Y; y++)
120 buf.SetPixel(x, y, col);
126 FillRectangle(
new Rectangle((
int)Math.Ceiling(r.X), (
int)Math.Ceiling(r.Y), (
int)Math.Ceiling(r.Width), (
int)Math.Ceiling(r.Height)), col);
130 for (
int x = r.X; x < r.Width + r.X; x++)
138 for (
int y = r.Y; y < r.Height + r.Y; y++)
149 DrawRectangle(
new Rectangle((
int)Math.Ceiling(r.X), (
int)Math.Ceiling(r.Y), (
int)Math.Ceiling(r.Width), (
int)Math.Ceiling(r.Height)));
154 if (r.Width == 1 && r.Height == 1)
156 double radiusx = r.Width / 2;
157 double radiusy = r.Height / 2;
159 for (
double a = 0.0; a < 360.0; a += 0.1)
161 double angle = a * System.Math.PI / 180;
164 x = (int)(radiusx * System.Math.Cos(angle) + radiusx + r.X);
165 y = (int)(radiusy * System.Math.Sin(angle) + radiusy + r.Y);
172 DrawEllipse(
new Rectangle((
int)Math.Ceiling(r.X), (
int)Math.Ceiling(r.Y), (
int)Math.Ceiling(r.Width), (
int)Math.Ceiling(r.Height)));
174 public void FillEllipse(
float xx,
float yy,
int w,
int h, ColorS c)
176 if (w <= 1 && w <= 1)
178 buf.SetPixel((
int)xx, (
int)yy, c);
181 double radiusx = w / 2;
182 double radiusy = h / 2;
184 for (
double a = 90; a < 270; a += 0.1)
186 double angle = a * System.Math.PI / 180;
187 x = (int)(radiusx * System.Math.Cos(angle) + radiusx + xx);
188 y = (int)(radiusy * System.Math.Sin(angle) + radiusy + yy);
189 double angle2 = (a + 180) * System.Math.PI / 180;
190 int x2 = (int)(radiusx * System.Math.Cos(angle2) + radiusx + xx);
196 FillEllipse(
new Rectangle((
int)Math.Ceiling(r.X), (
int)Math.Ceiling(r.Y), (
int)Math.Ceiling(r.Width), (
int)Math.Ceiling(r.Height)), c);
206 Bitmap bf =
buf.CopyInfo();
207 bf.Bytes =
new byte[
buf.Bytes.Length];
213 filler.Tolerance =
new ColorS(0, 0, 0);
217 System.Drawing.Point p =
new System.Drawing.Point(r.X + (r.Width / 2), r.Y + (r.Height / 2));
218 System.Drawing.Point? pp =
null;
220 for (
int x = r.X; x < r.Width + r.X; x++)
224 pp =
new System.Drawing.Point(x, p.Y);
228 filler.
FloodFill(
new AForge.Point(pp.Value.X,pp.Value.Y));
230 for (
int x = 0; x < bf.SizeX; x++)
232 for (
int y = 0; y < bf.SizeY; y++)
244 FillPolygon(pfs,
new Rectangle((
int)r.X, (
int)r.Y, (
int)r.Width, (
int)r.Height));
246 private static PointF[] polygon;
249 int j = polygon.Length - 1;
251 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;
265 private void DrawPolygon(PointF[] pfs, Bitmap bf, ColorS s)
267 for (
int i = 0; i < pfs.Length - 1; i++)
269 DrawLine((
int)pfs[i].X, (
int)pfs[i].Y, (
int)pfs[i + 1].X, (
int)pfs[i + 1].Y, bf, s);
271 DrawLine((
int)pfs[0].X, (
int)pfs[0].Y, (
int)pfs[pfs.Length - 1].X, (
int)pfs[pfs.Length - 1].Y, bf, s);
275 for (
int xx = x; xx < x2; xx++)
277 buf.SetPixel(xx, line, col);
System.Drawing.Graphics Graphics
The base class that the flood fill algorithms inherit from. Implements the basic flood filler functio...
void DrawEllipse(RectangleF r)
void FillRectangle(Rectangle r, ColorS col)
void FillEllipse(Rectangle r, ColorS c)
void FillPolygon(PointF[] pfs, RectangleF r)
bool PointInPolygon(int x, int y)
void DrawEllipse(Rectangle r)
void FillEllipse(RectangleF r, ColorS c)
void FillPolygon(PointF[] pfs, Rectangle r, ColorS c)
void DrawLine(PointF p, PointF p2)
void DrawScanline(int x, int x2, int line, ColorS col)
void DrawRectangle(RectangleF r)
void FillPolygon(PointF[] pfs, RectangleF r, ColorS c)
void FillEllipse(float xx, float yy, int w, int h, ColorS c)
void FillRectangle(RectangleF r, ColorS col)
static Graphics FromImage(Bitmap b)
void FillPolygon(PointF[] pfs, Rectangle r)
void DrawLine(int x, int y, int x2, int y2)
void DrawRectangle(Rectangle r)
Implements the QueueLinear flood fill algorithm using array-based pixel manipulation.
Pen(ColorS col, ushort w, int bitsPerPixel)
Pen(ColorS col, int w, int bitsPerPixel)