public void ScanLineFillEllipse(Graphics graph, Ellipse shape, Color color) { int rx = (int) Math.Round(shape.MajorAxis); int ry = (int)Math.Round(shape.MinorAxis); var o = Point.Round(shape.OrginalPoint.ToPoint()); var penline = new Pen(color, 1F); int x = 0, y = ry; int c1 = 2 * ry * ry * x, c2 = 2 * rx * rx * y; float p = ry * ry - rx * rx * ry + 0.25F * rx * rx; while (c1 < c2) { Fill2Line(o.X, o.Y, x, y, graph, penline); x++; if (p < 0) { c1 += 2 * ry * ry; p += c1 + ry * ry; } else { y--; c1 += 2 * ry * ry; c2 -= 2 * rx * rx; p += c1 - c2 + ry * ry; } } c1 = 2 * rx * rx * y; c2 = 2 * ry * ry * x; p = ry * ry * (x + 0.5F) * (x + 0.5F) + rx * rx * (y - 1) * (y - 1) - rx * rx * ry * ry; while (y != 0) { Fill2Line(o.X, o.Y, x, y, graph, penline); y--; if (p > 0) { c1 -= 2 * rx * rx; p += rx * rx - c1; } else { x++; c1 -= 2 * rx * rx; c2 += 2 * ry * ry; p += c2 - c1 + rx * rx; } } Fill2Line(o.X, o.Y, x, y, graph, penline); penline.Dispose(); }
private void DrawEllipse(Ellipse ellipse, Graphics graphs) { var path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(Util.GetShapeBound(ellipse)); path.CloseFigure(); using (var b = new SolidBrush(ellipse.FillColor)) using (var p = new Pen(ellipse.OutlineColor, ellipse.OutlineWidth)) { p.DashStyle = ellipse.OutlineDash; graphs.FillPath(b, path); //_filler.FillByScanline(graphs, ellipse, ellipse.FillColor); graphs.DrawPath(p, path); } }
public static IDrawingObject ReadDrawingObject(BinaryReader reader) { // read object type IDrawingObject obj = null; int type = reader.ReadInt32(); switch ((DrawingObjectType)type) { case DrawingObjectType.Shape: { // read shape type int shapeType = reader.ReadInt32(); ShapeBase shape; if ((ShapeType) shapeType == ShapeType.Ellipse) shape = new Ellipse(); else shape = new FreePencil(); //var shape = ShapeFactory.CreateShape((ShapeType) shapeType); // write shape location shape.Location = ReadPoint(reader); // write shape size shape.Size = ReadSize(reader); // write shape outline color shape.OutlineColor = ReadColor(reader); // write shape outline width shape.OutlineWidth = reader.ReadSingle(); // write shape outline dash shape.OutlineDash = (DashStyle) reader.ReadInt32(); // write shape fill color shape.FillColor = ReadColor(reader); if (shape.GetShapeType() != ShapeType.Ellipse) { // write count vertex var vcount = reader.ReadInt32(); for (int i = 0; i < vcount; i++) { Vertex v = ReadVertex(reader); shape.Vertices.Add(v); } } if (shape.GetShapeType() == ShapeType.Polygon || shape.GetShapeType() == ShapeType.Oblong || shape.GetShapeType() == ShapeType.IsoscelesTriangle) { var s = shape as PolygonBase; s.IsClosedFigure = true; } } break; } return obj; }