System.Drawing.Rectangle.Intersect C# (CSharp) Method

Intersect() public static method

Creates a rectangle that represents the intersection between a and b. If there is no intersection, null is returned.
public static Intersect ( Rectangle a, Rectangle b ) : Rectangle
a Rectangle
b Rectangle
return Rectangle
        public static Rectangle Intersect(Rectangle a, Rectangle b)
        {
            int x1 = Math.Max(a.X, b.X);
            int x2 = Math.Min(a.X + a.Width, b.X + b.Width);
            int y1 = Math.Max(a.Y, b.Y);
            int y2 = Math.Min(a.Y + a.Height, b.Y + b.Height);

            if (x2 >= x1 && y2 >= y1)
            {
                return new Rectangle(x1, y1, x2 - x1, y2 - y1);
            }

            return Empty;
        }

Same methods

Rectangle::Intersect ( System a, System b ) : System.Drawing.Rectangle
Rectangle::Intersect ( Rectangle rect ) : void
Rectangle::Intersect ( System rect ) : void

Usage Example

Beispiel #1
0
        void controller_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (!backproj)
            {
                Bitmap image = eventArgs.Frame;

                if (image == null)
                    return;

                if (parent.faceForm != null && !parent.faceForm.IsDisposed)
                {
                    MatchingTracker matching = parent.faceForm.faceController.Tracker as MatchingTracker;

                    Rectangle rect = new Rectangle(
                        matching.TrackingObject.Center.X,
                        0,
                        image.Width - matching.TrackingObject.Center.X,
                        matching.TrackingObject.Center.Y);

                 
                    rect.Intersect(new Rectangle(0, 0, image.Width, image.Height));

                     marker.Rectangles = new[] { matching.TrackingObject.Rectangle };
                     image = marker.Apply(image);
                }


                pictureBox.Image = image;
            }
        }
All Usage Examples Of System.Drawing.Rectangle::Intersect