GDI+ Clip Region allows 0.0f width pen to draw through
- From: Geoff <Geoff@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 7 May 2007 14:01:01 -0700
Here is my setup:
Windows Vista Ultimate
Visual Studio 2005
Intel Core 2 CPU 6600 @ 2.40 GHz
RAM: 2045 MB
..NET 2.0
The problem is:
Using a zero width pen I can draw into areas that are not part of the clip
region.
Create a simple Windows Forms application.
On the form place a panel.
Attach a method to the Paint event.
Inside the draw create two rectangles.
The first rectangle does not fit in the panel in this very specific manner:
the rectangle's right edge is outside the panel and the left edge is inside
the panel. In other words create a rectangle that is a wider than the panel.
The second rectangle does not intersect the first rectangle and is
completely inside the panel.
Create a region and make it infinite. Exclude rectangle one and rectangle
two from the region.
Set the clip of the graphics instance (found in the event args) to the
region just created using a combine mode of Intersect.
Now fill a rectangle that is bigger than the panel with some color to see if
the two rectangles are excluded from the fill, which they are.
Create a pen that has a zero width.
In a loop draw vertical lines across the panel. Notice how the lines draw
through rectangle one but not rectangle two.
If you change the pen size the lines will not draw through rectangle one or
rectangle two.
Any suggestions on how to still use a zero width pen and not draw inside the
rectangle one?
Is there a specific group for GDI+ to which I should post this problem?
Geoffrey Slinker
--- here is the code---
<DESIGNER CODE>
namespace ClipBug
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose( bool disposing )
{
if( disposing && ( components != null ) )
{
components.Dispose( );
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent( )
{
this.panel1 = new System.Windows.Forms.Panel( );
this.SuspendLayout( );
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Location = new System.Drawing.Point( 52, 44 );
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size( 491, 326 );
this.panel1.TabIndex = 0;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(
this.panel1_Paint );
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size( 625, 440 );
this.Controls.Add( this.panel1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout( false );
}
#endregion
private System.Windows.Forms.Panel panel1;
}
}
<FORM CODE>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ClipBug
{
public partial class Form1 : Form
{
public Form1( )
{
InitializeComponent( );
}
private void panel1_Paint( object sender, PaintEventArgs e )
{
Graphics graphics = e.Graphics;
graphics.PageUnit = GraphicsUnit.Inch;
RectangleF rectA = new RectangleF( 3.5f, 0.5f, 2.0f, 1.0f );
RectangleF rectB = new RectangleF( 3.5f, 2.0f, .5f, .5f );
//graphics.FillRectangle( Brushes.Beige, rect );
Region r = new Region( );
r.MakeInfinite( );
r.Exclude( rectA );
r.Exclude( rectB );
Region oldClip = graphics.Clip;
graphics.SetClip( r,
System.Drawing.Drawing2D.CombineMode.Intersect );
float x = 0.0f;
graphics.FillRectangle( Brushes.LightCoral, 0.0f, 0.0f, 1000.0f,
1000.0f );
Pen pen = new Pen( Brushes.Black, 0.0f );
for( int i = 0; i < 10000; i++ )
{
graphics.DrawLine( pen, x, 0.0f, x, 100.0f );
x += 0.1f;
}
pen.Dispose( );
}
}
}
.
- Follow-Ups:
- Prev by Date: Re: Draw Image Using GDI+ ( MDI Application using MFC)
- Next by Date: Creating a Bitmap using FromHBITMAP problem
- Previous by thread: Re: Draw Image Using GDI+ ( MDI Application using MFC)
- Next by thread: RE: GDI+ Clip Region allows 0.0f width pen to draw through
- Index(es):
Relevant Pages
|