本文整理汇总了C#中System.Drawing.Region.Xor方法的典型用法代码示例。如果您正苦于以下问题:C# Region.Xor方法的具体用法?C# Region.Xor怎么用?C# Region.Xor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Region
的用法示例。
在下文中一共展示了Region.Xor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ctor_GraphicsPath
public void ctor_GraphicsPath () {
GraphicsPath path = new GraphicsPath ();
path.AddRectangle (rect);
Region r1 = new Region (path);
r1.Xor (r);
Assert.IsTrue (r1.IsEmpty (t.Graphics));
}
示例2: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Region regionRing = new Region(outCircle.Path);
//形成圆环
regionRing.Xor(innerCircle.Path);
//截取部分圆环
regionRing.Intersect(clipRectangle);
e.Graphics.FillRegion(Brushes.Red, regionRing);
//画处边框
using (Pen p = new Pen(Brushes.Black))
{
e.Graphics.DrawPath(p, outCircle.Path);
e.Graphics.DrawPath(p, innerCircle.Path);
}
}
示例3: Form1_Paint
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect1 = new Rectangle(40, 40, 160, 160);
Rectangle rect2 = new Rectangle(90, 90, 160, 160);
Region rg1 = new Region(rect1);
Region rg2 = new Region(rect2);
g.DrawRectangle(Pens.Black, rect1);
g.DrawRectangle(Pens.Red, rect2);
// rg1.Intersect(rect2);
rg1.Xor(rect2);
g.FillRegion(Brushes.Blue , rg1);
g.Dispose();
}
示例4: CreateRectangleDragOutline
private static Region CreateRectangleDragOutline(Rectangle rect, int indent)
{
// Create region for whole of the new rectangle
Region region = new Region(rect);
// If the rectangle is to small to make an inner object from, then just use the outer
if ((indent <= 0) || (rect.Width <= 2 * indent) || (rect.Height <= 2 * indent))
return region;
rect.X += indent;
rect.Y += indent;
rect.Width -= 2 * indent;
rect.Height -= 2 * indent;
region.Xor(rect);
return region;
}
示例5: OnRenderSplitButtonBackground
protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
{
ToolStripSplitButton item = (ToolStripSplitButton) e.Item;
if ((e.Item.Selected || item.ButtonPressed) || item.DropDownButtonPressed)
{
if (!item.DropDownButtonPressed)
{
Rectangle dropDownButtonBounds = item.DropDownButtonBounds;
dropDownButtonBounds = new Rectangle(dropDownButtonBounds.Left + 1, dropDownButtonBounds.Top + 5, dropDownButtonBounds.Width - 3, dropDownButtonBounds.Height - 10);
using (Region region = new Region(new Rectangle(Point.Empty, e.Item.Size)))
{
region.Xor(dropDownButtonBounds);
e.Graphics.SetClip(region, CombineMode.Replace);
base.OnRenderSplitButtonBackground(e);
e.Graphics.SetClip(dropDownButtonBounds);
e.Graphics.TranslateTransform((float) item.DropDownButtonBounds.Width, 0f);
if (item.ButtonPressed && (base.BaseRenderer is ToolStripProfessionalRenderer))
{
using (ToolStripButton button2 = new ToolStripButton())
{
button2.Select();
button2.Size = e.Item.Size;
base.OnRenderButtonBackground(new ToolStripItemRenderEventArgs(e.Graphics, button2));
}
}
else
{
base.OnRenderSplitButtonBackground(e);
}
e.Graphics.ResetTransform();
e.Graphics.ResetClip();
}
}
else
{
base.OnRenderSplitButtonBackground(e);
}
}
if (!item.DropDownButtonPressed)
{
this.OnRenderArrow(new ToolStripArrowRenderEventArgs(e.Graphics, e.Item, item.DropDownButtonBounds, Color.Black, ArrowDirection.Right));
}
}
示例6: DrawRegionOperation
void DrawRegionOperation()
{
g = this.CreateGraphics();
Rectangle rect1 = new Rectangle(100, 100, 120, 120);
Rectangle rect2 = new Rectangle(70, 70, 120, 120);
Region rgn1 = new Region(rect1);
Region rgn2 = new Region(rect2);
g.DrawRectangle(Pens.Blue, rect1);
g.DrawRectangle(Pens.Red, rect2);
switch(rgnOperation)
{
case RegionOperation.Union:
rgn1.Union(rgn2);
break;
case RegionOperation.Complement:
rgn1.Complement(rgn2);
break;
case RegionOperation.Intersect:
rgn1.Intersect(rgn2);
break;
case RegionOperation.Exclude:
rgn1.Exclude(rgn2);
break;
case RegionOperation.Xor:
rgn1.Xor(rgn2);
break;
default:
break;
}
g.FillRegion(Brushes.Tomato, rgn1);
g.Dispose();
}
示例7: DrawRegionOperations
private void DrawRegionOperations()
{
g = this.CreateGraphics();
// Создаем два прямоугольника
Rectangle rect1 = new Rectangle(100, 100, 120, 120);
Rectangle rect2 = new Rectangle(70, 70, 120, 120);
// Создаем два региона
Region rgn1 = new Region(rect1);
Region rgn2 = new Region(rect2);
// рисуем прямоугольники
g.DrawRectangle(Pens.Green, rect1);
g.DrawRectangle(Pens.Black, rect2);
// обработаем перечисление и вызовем соответствующий метод
switch (rgnOperation)
{
case RegionOperations.Union:
rgn1.Union(rgn2);
break;
case RegionOperations.Complement:
rgn1.Complement(rgn2);
break;
case RegionOperations.Intersect:
rgn1.Intersect(rgn2);
break;
case RegionOperations.Exclude:
rgn1.Exclude(rgn2);
break;
case RegionOperations.Xor:
rgn1.Xor(rgn2);
break;
default:
break;
}
// Рисуем регион
g.FillRegion(Brushes.Blue, rgn1);
g.Dispose();
}
示例8: SmallXor_Self2
public void SmallXor_Self2 ()
{
Region region = new Region (sp2);
region.Xor (sp2);
CompareSmallRegion (region, sempty, 7, 7);
RectangleF[] scans = region.GetRegionScans (matrix);
Assert.AreEqual (0, scans.Length, "GetRegionScans");
}
示例9: SmallXor2
public void SmallXor2 ()
{
Region region = new Region (sp2);
region.Xor (sp1);
CompareSmallRegion (region, sxor, 7, 7);
RectangleF[] scans = region.GetRegionScans (matrix);
Assert.AreEqual (4, scans.Length, "GetRegionScans");
CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
CheckRectF ("[1]", 0, 2, 2, 1, scans[1]);
CheckRectF ("[2]", 3, 2, 2, 1, scans[2]);
CheckRectF ("[3]", 2, 3, 3, 2, scans[3]);
}
示例10: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
float valueStart = this.scaleFactor.ScaleScalar(this.rulerValue - offset);
float valueEnd = this.scaleFactor.ScaleScalar(this.rulerValue + 1.0f - offset);
float highlightStartPx = this.scaleFactor.ScaleScalar(this.highlightStart - offset);
float highlightEndPx = this.scaleFactor.ScaleScalar(this.highlightStart + this.highlightLength - offset);
RectangleF highlightRect;
RectangleF valueRect;
if (this.orientation == Orientation.Horizontal)
{
valueRect = new RectangleF(valueStart, this.ClientRectangle.Top, valueEnd - valueStart, this.ClientRectangle.Height);
highlightRect = new RectangleF(highlightStartPx, this.ClientRectangle.Top, highlightEndPx - highlightStartPx, this.ClientRectangle.Height);
}
else // if (this.orientation == Orientation.Vertical)
{
valueRect = new RectangleF(this.ClientRectangle.Left, valueStart, this.ClientRectangle.Width, valueEnd - valueStart);
highlightRect = new RectangleF(this.ClientRectangle.Left, highlightStartPx, this.ClientRectangle.Width, highlightEndPx - highlightStartPx);
}
if (!this.highlightEnabled)
{
highlightRect = RectangleF.Empty;
}
if (this.orientation == Orientation.Horizontal)
{
// This could be used in the future for making a DPI aware app. Needs a specific system layer though...
//e.Graphics.DrawLine(
// SystemPens.WindowText,
// UI.ScaleWidth(15),
// ClientRectangle.Top,
// UI.ScaleWidth(15),
// ClientRectangle.Bottom);
e.Graphics.DrawLine(
SystemPens.WindowText,
15,
ClientRectangle.Top,
15,
ClientRectangle.Bottom);
//string abbStringName = "MeasurementUnit." + this.MeasurementUnit.ToString() + ".Abbreviation";
//string abbString = PdnResources.GetString(abbStringName);
//e.Graphics.DrawString("Unit", Font, SystemBrushes.WindowText, UI.ScaleWidth(-2), 0);
e.Graphics.DrawString("nm", Font, SystemBrushes.WindowText, -2, 0);
}
Region clipRegion = new Region(highlightRect);
clipRegion.Xor(valueRect);
if (this.orientation == Orientation.Horizontal)
{
//clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height));
clipRegion.Exclude(new Rectangle(0, 0, 16, ClientRectangle.Height));
}
e.Graphics.SetClip(clipRegion, CombineMode.Replace);
DrawRuler(e, true);
clipRegion.Xor(this.ClientRectangle);
if (this.orientation == Orientation.Horizontal)
{
//clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height - 1));
clipRegion.Exclude(new Rectangle(0, 0, 16, ClientRectangle.Height - 1));
}
e.Graphics.SetClip(clipRegion, CombineMode.Replace);
DrawRuler(e, false);
}
示例11: SetClip
public void SetClip(Region region, CombineMode combineMode)
{
// We need to reset the clip that is active now so that the graphic
// states are correct when we set them.
ResetClip ();
switch (combineMode)
{
case CombineMode.Replace:
// Set our clip region by cloning the region that is passed for now
clipRegion = region.Clone ();
break;
case CombineMode.Intersect:
clipRegion.Intersect (region);
break;
case CombineMode.Union:
clipRegion.Union (region);
break;
case CombineMode.Exclude:
clipRegion.Exclude (region);
break;
case CombineMode.Xor:
clipRegion.Xor (region);
break;
default:
throw new NotImplementedException ("SetClip for CombineMode " + combineMode + " not implemented");
}
//Unlike the current path, the current clipping path is part of the graphics state.
//Therefore, to re-enlarge the paintable area by restoring the clipping path to a
//prior state, you must save the graphics state before you clip and restore the graphics
//state after you’ve completed any clipped drawing.
context.SaveState ();
if (clipRegion.IsEmpty) {
context.ClipToRect (CGRect.Empty);
} else {
//context.ClipToRect ((RectangleF)clipRegion.regionObject);
context.AddPath (clipRegion.regionPath);
context.ClosePath ();
context.Clip ();
}
clipSet++;
}
示例12: EmptyRegionWithInfiniteRegion
public void EmptyRegionWithInfiniteRegion ()
{
Region empty = new Region ();
empty.MakeEmpty ();
Assert.IsTrue (empty.IsEmpty (graphic), "IsEmpty");
Region region = new Region ();
Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
region.Union (empty);
Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");
region.Xor (empty);
Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");
region.Exclude (empty);
Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");
region.Intersect (empty);
Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");
region.MakeInfinite ();
region.Complement (empty);
Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
}
示例13: XorWithoutIntersection_Large
// libgdiplus: both region aren't considered as an intersection because they do
// not co-exists in the same 8x8 bitmap. In this case the xor function calls the
// union code (optimization).
public void XorWithoutIntersection_Large ()
{
Region region = new Region (sp1);
region.Xor (sp4);
CompareSmallRegion (region, ni_xor, 13, 5);
}
示例14: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
float valueStart = this.scaleFactor.ScaleScalar(this.rulerValue - offset);
float valueEnd = this.scaleFactor.ScaleScalar(this.rulerValue + 1.0f - offset);
float highlightStartPx = this.scaleFactor.ScaleScalar(this.highlightStart - offset);
float highlightEndPx = this.scaleFactor.ScaleScalar(this.highlightStart + this.highlightLength - offset);
RectangleF highlightRect;
RectangleF valueRect;
if (this.orientation == Orientation.Horizontal)
{
valueRect = new RectangleF(valueStart, this.ClientRectangle.Top, valueEnd - valueStart, this.ClientRectangle.Height);
highlightRect = new RectangleF(highlightStartPx, this.ClientRectangle.Top, highlightEndPx - highlightStartPx, this.ClientRectangle.Height);
}
else // if (this.orientation == Orientation.Vertical)
{
valueRect = new RectangleF(this.ClientRectangle.Left, valueStart, this.ClientRectangle.Width, valueEnd - valueStart);
highlightRect = new RectangleF(this.ClientRectangle.Left, highlightStartPx, this.ClientRectangle.Width, highlightEndPx - highlightStartPx);
}
if (!this.highlightEnabled)
{
highlightRect = RectangleF.Empty;
}
if (this.orientation == Orientation.Horizontal)
{
e.Graphics.DrawLine(
SystemPens.WindowText,
UI.ScaleWidth(15),
ClientRectangle.Top,
UI.ScaleWidth(15),
ClientRectangle.Bottom);
string abbStringName = "MeasurementUnit." + this.MeasurementUnit.ToString() + ".Abbreviation";
string abbString = PdnResources.GetString(abbStringName);
e.Graphics.DrawString(abbString, Font, SystemBrushes.WindowText, UI.ScaleWidth(-2), 0);
}
Region clipRegion = new Region(highlightRect);
clipRegion.Xor(valueRect);
if (this.orientation == Orientation.Horizontal)
{
clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height));
}
e.Graphics.SetClip(clipRegion, CombineMode.Replace);
DrawRuler(e, true);
clipRegion.Xor(this.ClientRectangle);
if (this.orientation == Orientation.Horizontal)
{
clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height - 1));
}
e.Graphics.SetClip(clipRegion, CombineMode.Replace);
DrawRuler(e, false);
clipRegion.Dispose();
}
示例15: TestXor
public void TestXor()
{
Bitmap bmp = new Bitmap (600, 800);
Graphics dc = Graphics.FromImage (bmp);
Matrix matrix = new Matrix ();
RectangleF [] rects;
Rectangle rect1 = new Rectangle (380, 30, 60, 80);
Rectangle rect2 = new Rectangle (410, 40, 60, 80);
Region rgn1 = new Region (rect1);
Region rgn2 = new Region (rect2);
rgn1.Xor (rgn2);
rects = rgn1.GetRegionScans (matrix);
Assert.AreEqual (4, rects.Length);
Assert.AreEqual (380, rects[0].X);
Assert.AreEqual (30, rects[0].Y);
Assert.AreEqual (60, rects[0].Width);
Assert.AreEqual (10, rects[0].Height);
Assert.AreEqual (380, rects[1].X);
Assert.AreEqual (40, rects[1].Y);
Assert.AreEqual (30, rects[1].Width);
Assert.AreEqual (70, rects[1].Height);
Assert.AreEqual (440, rects[2].X);
Assert.AreEqual (40, rects[2].Y);
Assert.AreEqual (30, rects[2].Width);
Assert.AreEqual (70, rects[2].Height);
Assert.AreEqual (410, rects[3].X);
Assert.AreEqual (110, rects[3].Y);
Assert.AreEqual (60, rects[3].Width);
Assert.AreEqual (10, rects[3].Height);
}