Line() public static method

Draw a line on the specified image.
The source image has incorrect pixel format.
public static Line ( BitmapData imageData, IntPoint point1, IntPoint point2, Color color ) : void
imageData System.Drawing.Imaging.BitmapData Source image data to draw on.
point1 IntPoint The first point to connect.
point2 IntPoint The second point to connect.
color Color Line's color.
return void
Example #1
0
        /// <summary>
        ///   Draws the line to a given image.
        /// </summary>
        ///
        /// <param name="image">The image where this Hough line should be drawn to.</param>
        /// <param name="color">The color to be used when drawing the line.</param>
        ///
        public void Draw(UnmanagedImage image, Color color)
        {
            // get line's radius and theta values
            int    r = this.Radius;
            double t = this.Theta;

            // check if line is in lower part of the image
            if (r < 0)
            {
                t += 180;
                r  = -r;
            }

            // convert degrees to radians
            t = (t / 180) * Math.PI;

            // get image centers (all coordinate are measured relative to center)
            int w2 = image.Width / 2;
            int h2 = image.Height / 2;

            double x0 = 0, x1 = 0, y0 = 0, y1 = 0;

            if (this.Theta != 0)
            {
                // none-vertical line
                x0 = -w2; // most left point
                x1 = w2;  // most right point

                // calculate corresponding y values
                y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t);
                y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t);
            }
            else
            {
                // vertical line
                x0 = this.Radius;
                x1 = this.Radius;

                y0 = h2;
                y1 = -h2;
            }

            // draw line on the image
            Drawing.Line(image,
                         new IntPoint((int)x0 + w2, h2 - (int)y0),
                         new IntPoint((int)x1 + w2, h2 - (int)y1),
                         Color.Red);
        }