SampleApp.MainForm.pictureBox_Paint C# (CSharp) Method

pictureBox_Paint() private method

private pictureBox_Paint ( object sender, PaintEventArgs e ) : void
sender object
e PaintEventArgs
return void
        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (pictureBox.Image != null)
            {
                int cx = imageSize.Width / 2;
                int cy = imageSize.Height / 2;

                for (int i = 0; i < 4; i++)
                {
                    if (imagePoints[i] != emptyPoint)
                    {
                        using (Brush brush = new SolidBrush(pointsColors[i]))
                        {
                            g.FillEllipse(brush, new Rectangle(
                                (int)(cx + imagePoints[i].X - 3),
                                (int)(cy - imagePoints[i].Y - 3),
                                7, 7));
                        }
                    }
                }

                if ((isPoseEstimated) && (pointIndexToLocate == -1))
                {
                    Accord.Point[] projectedAxes = PerformProjection(axesModel,
                        // create tranformation matrix
                        Matrix4x4.CreateTranslation(translationVector) *       // 3: translate
                        Matrix4x4.CreateFromRotation(rotationMatrix) *         // 2: rotate
                        Matrix4x4.CreateDiagonal(
                            new Vector4(modelRadius, modelRadius, modelRadius, 1)), // 1: scale
                        imageSize.Width
                    );

                    using (Pen pen = new Pen(Color.Blue, 5))
                    {
                        g.DrawLine(pen,
                            cx + projectedAxes[0].X, cy - projectedAxes[0].Y,
                            cx + projectedAxes[1].X, cy - projectedAxes[1].Y);
                    }

                    using (Pen pen = new Pen(Color.Red, 5))
                    {
                        g.DrawLine(pen,
                            cx + projectedAxes[0].X, cy - projectedAxes[0].Y,
                            cx + projectedAxes[2].X, cy - projectedAxes[2].Y);
                    }

                    using (Pen pen = new Pen(Color.Lime, 5))
                    {
                        g.DrawLine(pen,
                            cx + projectedAxes[0].X, cy - projectedAxes[0].Y,
                            cx + projectedAxes[3].X, cy - projectedAxes[3].Y);
                    }
                }
            }
        }
MainForm