本文整理汇总了C#中Region.Xor方法的典型用法代码示例。如果您正苦于以下问题:C# Region.Xor方法的具体用法?C# Region.Xor怎么用?C# Region.Xor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Region
的用法示例。
在下文中一共展示了Region.Xor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValueRec
public Region GetValueRec()
{
Region r;
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse((float)((.05 - vm.CircleWidth / 200f) * vm.Width), (float)((.05 - vm.CircleWidth / 200f) * vm.Height), (float)(.90 + vm.CircleWidth / 100f) * vm.Width, (float)(.90 + vm.CircleWidth / 100f) * vm.Height);
r = new Region(gp);
gp = new GraphicsPath();
gp.AddEllipse((float)((.05 + vm.CircleWidth / 200f) * vm.Width), (float)((.05 + vm.CircleWidth / 200f) * vm.Height), (float)(.90 - vm.CircleWidth / 100f) * vm.Width, (float)(.90 - vm.CircleWidth / 100f) * vm.Height);
r.Xor(gp);
return r;
}
示例2: Main
public static void Main ()
{
Bitmap bmp = new Bitmap (600, 300);
Graphics dc = Graphics.FromImage (bmp);
Font fnt = new Font ("Arial", 8);
Font fnttitle = new Font ("Arial", 8, FontStyle.Underline);
Matrix matrix = new Matrix ();
GraphicsPath patha = new GraphicsPath ();
GraphicsPath pathb = new GraphicsPath ();
Pen redPen = new Pen (Color.Red, 2);
Region rgn1;
Region rgn2;
int x = 0;
SolidBrush whiteBrush = new SolidBrush (Color.White);
dc.DrawString ("Region samples using GraphicsPath", fnttitle, whiteBrush, 5, 5);
/* First*/
patha.AddLine (60, 40, 90, 90);
patha.AddLine (90, 90, 10, 90);
patha.AddLine (10, 90, 60, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse(30, 55, 60, 60);
dc.DrawPath(redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Complement (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Complement (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 10, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Second*/
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
patha.AddLine (90+x, 90, 10+x, 90);
patha.AddLine (10+x, 90, 60+x, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse (30+x, 55, 60, 60);
dc.DrawPath(redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Exclude (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Exclude (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 140, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Third*/
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
patha.AddLine (90+x, 90, 10+x, 90);
patha.AddLine (10+x, 90, 60+x, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse (30+x, 55, 60, 60);
dc.DrawPath (redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Intersect (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Intersect (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 270, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Four*/
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
patha.AddLine (90+x, 90, 10+x, 90);
patha.AddLine (10+x, 90, 60+x, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse (30+x, 55, 60, 60);
dc.DrawPath (redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Xor (rgn2);
dc.FillRegion(Brushes.Blue, rgn1);
dc.DrawString ("Xor (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 380, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Fifth */
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
//.........这里部分代码省略.........
示例3: IsFit
public bool IsFit(Point[] points)
{
// Note: rigorously calculating distance(point,ellipse) is very hard...
// overlay the regions and compare the areas, for now.
using (GraphicsPath polygp = new GraphicsPath())
using (GraphicsPath elligp = new GraphicsPath())
using (Matrix m = new Matrix())
{
// Set up gp for stroke.
polygp.AddPolygon(points);
// Set up gp for ellipse.
elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);
m.Translate((float)cx,(float)cy);
m.Rotate((float)th);
elligp.Transform(m);
// Prepare regions for area-calculation.
using (Region xor = new Region(elligp))
using (Region isc = new Region(elligp))
{
xor.Xor(polygp);
isc.Intersect(polygp);
float badarea = Geometry.CalculateArea(xor);
float iscarea = Geometry.CalculateArea(isc);
float ratio = iscarea/badarea;
//heuristic: 10.0 seems about right.
return (ratio > 10f);
}
}
}
示例4: Main
public static void Main ()
{
Bitmap bmp = new Bitmap (600, 800);
Graphics dc = Graphics.FromImage (bmp);
Font fnt = new Font ("Arial", 8);
Font fnttitle = new Font("Arial", 8, FontStyle.Underline);
Matrix matrix = new Matrix ();
int x = 0;
Rectangle rect1, rect2, rect3, rect4;
Region rgn1, rgn2, rgn3, rgn4;
bool complement = true, exclude = true, union = true, xor = true, intersect = true;
SolidBrush whiteBrush = new SolidBrush (Color.White);
dc.DrawString ("Region samples using two Rectangle classes", fnttitle, whiteBrush, 5, 5);
/* First */
if (complement) {
rect1 = new Rectangle (20, 30, 60, 80);
rect2 = new Rectangle (50, 40, 60, 80);
rgn1 = new Region (rect1);
rgn2 = new Region (rect2);
dc.DrawRectangle (Pens.Green, rect1);
dc.DrawRectangle (Pens.Red, rect2);
rgn1.Complement (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Complement (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 10, 130);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
DumpRegion (rgn1);
}
/* Second */
if (exclude) {
rect3 = new Rectangle (130, 30, 60, 80);
rect4 = new Rectangle (170, 40, 60, 80);
rgn3 = new Region (rect3);
rgn4 = new Region (rect4);
dc.DrawRectangle (Pens.Green, rect3);
dc.DrawRectangle (Pens.Red, rect4);
rgn3.Exclude (rgn4);
dc.FillRegion (Brushes.Blue, rgn3);
dc.DrawString ("Exclude (" + rgn3.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 130, 130);
dc.DrawRectangles (Pens.Yellow, rgn3.GetRegionScans (matrix));
DumpRegion (rgn3);
}
/* Third */
if (intersect) {
Rectangle rect5 = new Rectangle (260, 30, 60, 80);
Rectangle rect6 = new Rectangle (290, 40, 60, 80);
Region rgn5 = new Region (rect5);
Region rgn6 = new Region (rect6);
dc.DrawRectangle (Pens.Green, rect5);
dc.DrawRectangle (Pens.Red, rect6);
rgn5.Intersect (rgn6);
dc.FillRegion (Brushes.Blue, rgn5);
dc.DrawString ("Intersect (" + rgn5.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 270, 130);
dc.DrawRectangles (Pens.Yellow, rgn5.GetRegionScans (matrix));
DumpRegion (rgn5);
}
/* Four */
if (xor) {
Rectangle rect7 = new Rectangle (380, 30, 60, 80);
Rectangle rect8 = new Rectangle (410, 40, 60, 80);
Region rgn7 = new Region (rect7);
Region rgn8 = new Region (rect8);
dc.DrawRectangle (Pens.Green, rect7);
dc.DrawRectangle (Pens.Red, rect8);
rgn7.Xor (rgn8);
dc.FillRegion (Brushes.Blue, rgn7);
dc.DrawString ("Xor (" + rgn7.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 400, 130);
dc.DrawRectangles (Pens.Yellow, rgn7.GetRegionScans (matrix));
DumpRegion (rgn7);
}
/* Fifht */
if (union) {
Rectangle rect9 = new Rectangle (500, 30, 60, 80);
Rectangle rect10 = new Rectangle (520, 40, 60, 80);
Region rgn9 = new Region(rect9);
Region rgn10 = new Region(rect10);
dc.DrawRectangle (Pens.Green, rect9);
dc.DrawRectangle (Pens.Red, rect10);
rgn9.Union(rgn10);
dc.FillRegion (Brushes.Blue, rgn9);
dc.DrawString ("Union (" + rgn9.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 530, 130);
dc.DrawRectangles (Pens.Yellow, rgn9.GetRegionScans (matrix));
DumpRegion (rgn9);
}
dc.DrawString ("Region samples using three Rectangle class", fnttitle, whiteBrush, 5, 155);
/* First */
x = 0;
if (complement) {
rect1 = new Rectangle (20+x, 180, 40, 50);
//.........这里部分代码省略.........