Ejemplo n.º 1
0
 protected void DrawPoints(List <SeriesFigure> figures, System.Drawing.Pen gdiPen, float d)
 {
     foreach (SeriesFigure figure in figures)
     {
         PointF point = figure.Points[0];
         point.X -= d / 2;
         point.Y -= d / 2;
         RectangleF rect = new RectangleF(point, new SizeF(d, d));
         GdiGraphics.DrawEllipse(gdiPen, rect);
     }
 }
Ejemplo n.º 2
0
 protected void DrawPath(List <SeriesFigure> figures, System.Drawing.Pen gdiPen)
 {
     foreach (var figure in figures) // could do parallel For loop here...
     {
         var points     = figure.Points;
         var pointCount = figure.Points.Count;
         for (int i = 0; i < pointCount - 1; i++)
         {
             GdiGraphics.DrawLine(gdiPen, points[i], points[i + 1]);
         }
     }
 }
Ejemplo n.º 3
0
        private static Bitmap MarkAngles(Bitmap image, double degrees)
        {
            var radians  = degrees * (Math.PI / 180);
            var blackPen = new System.Drawing.Pen(Color.LightGray, 1);

            using (var graphics = Graphics.FromImage(image))
            {
                for (var currAngle = 0.0; currAngle < Math.PI / 2; currAngle += radians)
                {
                    DrawLineAtAngle(image, currAngle, graphics, blackPen);
                    DrawLineAtAngle(image, -currAngle, graphics, blackPen);
                }
            }

            return(image);
        }
Ejemplo n.º 4
0
        protected void DrawFilledPath(List <SeriesFigure> figures, System.Drawing.Pen gdiPen, System.Drawing.SolidBrush gdiBrush)
        {
            var path = new System.Drawing.Drawing2D.GraphicsPath();

            foreach (var figure in figures) // could do parallel For loop here...
            {
                path.StartFigure();

                var points     = figure.Points;
                var pointCount = figure.Points.Count;
                for (int i = 0; i < pointCount - 1; i++)
                {
                    path.AddLine(points[i], points[i + 1]);
                }
            }
            path.CloseAllFigures();
            GdiGraphics.FillPath(gdiBrush, path);
            GdiGraphics.DrawPath(gdiPen, path);
        }
Ejemplo n.º 5
0
        private void PaintChars(InPage page, long id)
        {
            float[] charHeight = new float[500];

            int    index  = 0;
            Bitmap cloned = Interpress.Library.Libraries.DbtLibrary.Image.Image.Clone(page.Img);

            using (Graphics g = Graphics.FromImage(cloned))
                foreach (var item in page.Zones)
                {
                    foreach (var itemChar in item.Chars)
                    {
                        Pen pen = new System.Drawing.Pen(staticsolidBrushes[index++ % staticsolidBrushes.Length], 1);
                        g.DrawRectangle(pen, itemChar.Rect.X, itemChar.Rect.Y, itemChar.Rect.Width, itemChar.Rect.Height);
                    }
                }
            string fileName = "c:\\temp\\" + id + "_char.jpg";

            cloned.Save(fileName);
            //imageviewerright.LoadImages(new List<byte[]>() { File.ReadAllBytes(fileName) });
            cloned.Dispose();
        }
Ejemplo n.º 6
0
 private void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) => GdiGraphics.DrawRectangle(pen, System.Drawing.Rectangle.Round(rect));
Ejemplo n.º 7
0
        private static void DrawFillPattern(Graphics g, FillPattern fillPattern)
        {
            Stopwatch sw = Stopwatch.StartNew();

            if (fillPattern == null)
            {
                return;
            }

            float matrixScale = 1000;

            try
            {
                var width = 30;

                var height = 30;

                var rect = new System.Drawing.Rectangle(0, 0, (int)width, (int)height);

                var rect_border = new System.Drawing.Rectangle(0, 0, (int)width - 1, (int)height - 1);
                Pen myPen       = new Pen(System.Drawing.Color.FromArgb(0, 255, 220), 1);

                g.DrawRectangle(myPen, rect_border);

                var centerX = (rect.Left + rect.Left + rect.Width) / 2;

                var centerY = (rect.Top + rect.Top + rect.Height) / 2;

                g.TranslateTransform(centerX, centerY);

                var rectF = new System.Drawing.Rectangle(-1, -1, 2, 2);

                g.FillRectangle(System.Drawing.Brushes.Transparent, rectF);

                g.ResetTransform();

                var fillGrids = fillPattern.GetFillGrids();

                foreach (var fillGrid in fillGrids)
                {
                    var degreeAngle = (float)fillGrid.Angle * 180 / Math.PI;

                    var pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(0, 255, 220))
                    {
                        Width = 1f / matrixScale
                    };

                    float dashLength = 1;

                    var segments = fillGrid.GetSegments();

                    if (segments.Count > 0)
                    {
                        pen.DashPattern = segments
                                          .Select(s => Math.Max(float.Epsilon, Convert.ToSingle(s)))
                                          .ToArray();

                        dashLength = pen.DashPattern.Sum();
                    }

                    g.ResetTransform();

                    var rotateMatrix = new System.Drawing.Drawing2D.Matrix();
                    rotateMatrix.Rotate((float)degreeAngle);

                    var matrix = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1,
                                                                     centerX, centerY);

                    matrix.Scale(matrixScale, matrixScale);

                    matrix.Translate((float)fillGrid.Origin.U,
                                     (float)fillGrid.Origin.V);

                    var backMatrix = matrix.Clone();
                    backMatrix.Multiply(rotateMatrix);
                    matrix.Multiply(rotateMatrix);

                    var offset = (-10) * dashLength;
                    matrix.Translate(offset, 0);
                    backMatrix.Translate(offset, 0);

                    bool   moving_forward = true;
                    bool   moving_back    = true;
                    int    safety         = 500;
                    double alternator     = 0;
                    while (moving_forward || moving_back) // draw segments shifting and offsetting each time
                    {
                        var rectF1 = new RectangleF(-2 / matrixScale, -2 / matrixScale, 4 / matrixScale, 4 / matrixScale);

                        if (moving_forward && LineIntersectsRect(matrix, rect))
                        {
                            g.Transform = matrix;
                            g.DrawLine(pen, new PointF(0, 0), new PointF(100, 0));
                        }
                        else
                        {
                            moving_forward = false;
                        }

                        if (moving_back && LineIntersectsRect(backMatrix, rect))
                        {
                            g.Transform = backMatrix;
                            g.DrawLine(pen, new PointF(0, 0), new PointF(100, 0));
                        }
                        else
                        {
                            moving_back = false;
                        }

                        if (safety == 0)
                        {
                            break;
                        }
                        else
                        {
                            --safety;
                        }

                        matrix.Translate((float)fillGrid.Shift, (float)fillGrid.Offset);
                        backMatrix.Translate(-(float)fillGrid.Shift, -(float)fillGrid.Offset);

                        alternator += fillGrid.Shift;
                        if (Math.Abs(alternator) > Math.Abs(offset))
                        {
                            matrix.Translate(offset, 0);
                            backMatrix.Translate(offset, 0);
                            alternator = 0d;
                        }
                    }
                }

                sw.Stop();
                g.ResetTransform();

                Pen p = new Pen(System.Drawing.Color.Teal);
                p.Width = 1f / matrixScale;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }