本文整理匯總了C#中System.Drawing.Region.Clone方法的典型用法代碼示例。如果您正苦於以下問題:C# Region.Clone方法的具體用法?C# Region.Clone怎麽用?C# Region.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Region
的用法示例。
在下文中一共展示了Region.Clone方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: BlockRegions
static BlockRegions()
{
int n = Constants.PROJ_WIDTH / 4;
WholeBlock = new Region();
WholeBlock.MakeEmpty();
for (int i = 0; i <= n; i++)
{
WholeBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i, i * 4 + 2, Constants.PROJ_HEIGHT - 2 * i));
}
WholeBlock.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH, Constants.PROJ_HEIGHT));
InnerBlock = new Region();
InnerBlock.MakeEmpty();
for (int i = 0; i <= n; i++)
{
InnerBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i + 1, i * 4 + 2, Constants.PROJ_HEIGHT - 2 - 2 * i));
}
InnerBlock.Intersect(new Rectangle(1, 1, Constants.PROJ_WIDTH - 2, Constants.PROJ_HEIGHT - 2));
OuterBorder = WholeBlock.Clone();
OuterBorder.Exclude(InnerBlock);
Top = InnerBlock.Clone();
Top.Translate(0, -Constants.BLOCK_HEIGHT);
Top.Intersect(InnerBlock);
Left = InnerBlock.Clone();
Left.Exclude(Top);
Top.Translate(0, 1);
Left.Exclude(Top);
Top.Translate(0, -1);
Right = Left.Clone();
Left.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));
Right.Intersect(new Rectangle(Constants.PROJ_WIDTH / 2 + 1, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));
InnerBorder = InnerBlock.Clone();
InnerBorder.Exclude(Top);
InnerBorder.Exclude(Left);
InnerBorder.Exclude(Right);
}
示例2: Clipping
/// <summary>
/// Initialize a new instance of the Clipping class.
/// </summary>
/// <param name="graphics">Graphics context.</param>
/// <param name="path">Path to clip.</param>
/// <param name="exclude">Exclude path from clipping.</param>
public Clipping(Graphics graphics, GraphicsPath path, bool exclude)
{
// Cache graphics instance
_graphics = graphics;
// Save the existing clipping region
_previousRegion = _graphics.Clip;
// Add clipping of path to existing clipping region
_newRegion = _previousRegion.Clone();
if (exclude)
_newRegion.Exclude(path);
else
_newRegion.Intersect(path);
_graphics.Clip = _newRegion;
}
示例3: Paint
/// <summary>
/// Paints the shape on the canvas
/// </summary>
/// <param name="g"></param>
///
public override void Paint(System.Drawing.Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle toggleNode = Rectangle.Empty; //the [+] [-]
Point[] pts = new Point[12]
{
new Point(rectangle.X,rectangle.Y), //0
new Point(rectangle.X+bshift,rectangle.Y), //1
new Point(rectangle.Right-bshift,rectangle.Y), //2
new Point(rectangle.Right,rectangle.Y), //3
new Point(rectangle.Right,rectangle.Y+bshift), //4
new Point(rectangle.Right,rectangle.Bottom-bshift), //5
new Point(rectangle.Right,rectangle.Bottom), //6
new Point(rectangle.Right-bshift,rectangle.Bottom), //7
new Point(rectangle.X+bshift,rectangle.Bottom), //8
new Point(rectangle.X,rectangle.Bottom), //9
new Point(rectangle.X,rectangle.Bottom - bshift), //10
new Point(rectangle.X,rectangle.Y+bshift), //11
};
path = new GraphicsPath();
path.AddBezier(pts[11],pts[0],pts[0],pts[1]);
path.AddLine(pts[1],pts[2]);
path.AddBezier(pts[2],pts[3],pts[3],pts[4]);
path.AddLine(pts[4],pts[5]);
path.AddBezier(pts[5],pts[6],pts[6],pts[7]);
path.AddLine(pts[7],pts[8]);
path.AddBezier(pts[8],pts[9],pts[9],pts[10]);
path.AddLine(pts[10],pts[11]);
path.CloseFigure();
region = new Region(path);
shapeBrush = new LinearGradientBrush(rectangle,this.shapeColor,Color.WhiteSmoke,0f);
// start Draw Shadow
shadow = region.Clone();
shadow.Translate(5, 5);
//add the amount of children
if (childNodes.Count > 0)
{
plus = " [" + childNodes.Count + "]";
}
else
{
plus = "";
}
g.FillRegion(new SolidBrush(Color.Gainsboro), shadow);
//g.DrawPath(new Pen(Color.Gainsboro,1), shadow);
//End Draw Shadow
g.FillRegion(shapeBrush, region);
if (hovered || isSelected)
pen = thickPen;
else
pen = blackPen;
g.DrawPath(pen, path);
if (text != string.Empty)
{
//g.DrawString(text + plus,font,Brushes.Black, rectangle.X+5,rectangle.Y+5);
g.DrawString(text,font,Brushes.Black, rectangle.X+5,rectangle.Y+5);
}
//draw the [+] expansion shape
if (childNodes.Count > 0)
{
switch(site.LayoutDirection)
{
case TreeDirection.Vertical:
toggleNode = new Rectangle(Left + this.Width/2 - 5, Bottom, 10, 10);
break;
case TreeDirection.Horizontal:
toggleNode = new Rectangle(Right , Top +Height/2-5 , 10, 10);
break;
}
//Draw [ ]
g.FillRectangle(new SolidBrush(Color.White), toggleNode);
g.DrawRectangle(blackPen, toggleNode);
//Draw -
g.DrawLine(blackPen, (toggleNode.X + 2), (toggleNode.Y + (toggleNode.Height / 2)), (toggleNode.X + (toggleNode.Width - 2)), (toggleNode.Y + (toggleNode.Height / 2)) );
if (!this.Expanded)
//.........這裏部分代碼省略.........
示例4: CreateFromDesktopImageInClippedRegion
public static BitmapPosData CreateFromDesktopImageInClippedRegion(Region rg, Point[] ptPath)
{
Console.WriteLine("CopyDesktopImageToClippedRegion");
BitmapPosData data = null;
int screenX;
int screenY;
IntPtr hBmp;
IntPtr hdcScreen = GetDC(GetDesktopWindow());
IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);
screenX = GetSystemMetrics(0);
screenY = GetSystemMetrics(1);
hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);
if (hBmp != IntPtr.Zero)
{
IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);
SelectObject(hdcCompatible, hOldBmp);
DeleteDC(hdcCompatible);
ReleaseDC(GetDesktopWindow(), hdcScreen);
Bitmap bmpDt = System.Drawing.Image.FromHbitmap(hBmp);
Graphics gd = Graphics.FromImage(bmpDt);
RectangleF rc = rg.GetBounds(gd);
Bitmap bmpClip = new Bitmap((int)rc.Width, (int)rc.Height);
Graphics gt = Graphics.FromImage(bmpClip);
Region rgnTempPict = rg.Clone();
rgnTempPict.Translate(-rc.X, -rc.Y);
gt.SetClip(rgnTempPict, System.Drawing.Drawing2D.CombineMode.Replace);
RectangleF rc2 = rg.GetBounds(gt);
gt.DrawImage(bmpDt, new Rectangle(0, 0, bmpClip.Width, bmpClip.Height), new Rectangle((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), GraphicsUnit.Pixel);
for (int i = 0; i < ptPath.Length; i++)
{
ptPath[i].Offset((int)-rc.X, (int)-rc.Y);
}
data = new BitmapPosData(bmpClip, rgnTempPict.Clone(), new Point(0, 0), ptPath);
rgnTempPict.Dispose();
gd.Dispose();
gt.Dispose();
DeleteObject(hBmp);
GC.Collect();
}
return data;
}
示例5: PdnRegion
public PdnRegion(Region region, bool takeOwnership)
{
if (takeOwnership)
{
this.gdiRegion = region;
}
else
{
this.gdiRegion = region.Clone();
}
}
示例6: UseClipping
/// <summary>
/// Initialize a new instance of the UseClipping class.
/// </summary>
/// <param name="g">Graphics instance.</param>
/// <param name="region">Clipping region.</param>
public UseClipping(Graphics g, Region region)
{
_g = g;
_old = g.Clip;
Region clip = _old.Clone();
clip.Intersect(region);
_g.Clip = clip;
}
示例7: CopyDesktopImageInClippedRegion
public void CopyDesktopImageInClippedRegion(Region rg, Point[] ptPath)
{
Console.WriteLine("CopyDesktopImageToClippedRegion");
int screenX;
int screenY;
IntPtr hBmp;
IntPtr hdcScreen = GetDC(GetDesktopWindow());
IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);
screenX = GetSystemMetrics(0);
screenY = GetSystemMetrics(1);
hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);
if (hBmp != IntPtr.Zero)
{
IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);
SelectObject(hdcCompatible, hOldBmp);
DeleteDC(hdcCompatible);
ReleaseDC(GetDesktopWindow(), hdcScreen);
Bitmap bmpDt = System.Drawing.Image.FromHbitmap(hBmp);
Graphics gd = Graphics.FromImage(bmpDt);
RectangleF rc = rg.GetBounds(gd);
Bitmap bmpClip = new Bitmap((int)rc.Width, (int)rc.Height);
Graphics gt = Graphics.FromImage(bmpClip);
Region rgnTempPict = rg.Clone();
rgnTempPict.Translate(-rc.X, -rc.Y);
gt.SetClip(rgnTempPict, System.Drawing.Drawing2D.CombineMode.Replace);
RectangleF rc2 = rg.GetBounds(gt);
gt.DrawImage(bmpDt, new Rectangle(0, 0, bmpClip.Width, bmpClip.Height), new Rectangle((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), GraphicsUnit.Pixel);
for (int i = 0; i < ptPath.Length; i++)
{
ptPath[i].Offset((int)-rc.X, (int)-rc.Y);
}
mCopiedBmpData = new FormNote.BitmapPosData(bmpClip, rgnTempPict.Clone(), new Point(0, 0), ptPath);
/*
//temp image for moving (transparent)
if (mPickedBmpDataTmp != null)
{
mPickedBmpDataTmp.Dispose();
mPickedBmpDataTmp = null;
}
mPickedBmpDataTmp = new BitmapPosData();
mPickedBmpDataTmp.location = mPickedBmpData.location;
mPickedBmpDataTmp.region = mPickedBmpData.region.Clone();
mPickedBmpDataTmp.bmp = new Bitmap(mPickedBmpData.bmp);
for (int y = 0; y < mPickedBmpDataTmp.bmp.Height; y++)
{
for (int x = 0; x < mPickedBmpDataTmp.bmp.Width; x++)
{
Color c = mPickedBmpDataTmp.bmp.GetPixel(x, y);
Color cc = Color.FromArgb(127, c.R, c.G, c.B);
mPickedBmpDataTmp.bmp.SetPixel(x, y, cc);
}
}
*/
rgnTempPict.Dispose();
gd.Dispose();
gt.Dispose();
DeleteObject(hBmp);
GC.Collect();
}
}
示例8: InvalidateOverlays
public void InvalidateOverlays(Region screenRegion)
{
for (int i = this.overlayList.Count - 1; i >= 0; i--)
{
Control control = this.overlayList[i] as Control;
if (control != null)
{
Rectangle bounds = control.Bounds;
bounds.Location = control.PointToScreen(control.Location);
using (Region region = screenRegion.Clone())
{
region.Intersect(bounds);
region.Translate(-bounds.X, -bounds.Y);
control.Invalidate(region);
}
}
}
}
示例9: 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++;
}
示例10: PushClip
/// <summary>
/// Pushes the current clip onto the clip stack and sets clip of the graphics context to
/// the intersection of the current clip and the given clip.
/// </summary>
/// <remarks>
/// The intersection of the current local clip and the new local clip is also pushed onto
/// the local clip stack.
/// </remarks>
/// <param name="aClip">The clip to push.</param>
public virtual void PushClip(Region aClip) {
RectangleF newLocalClip = RectangleF.Intersect(LocalClip, aClip.GetBounds(graphics));
localClipStack.Push(newLocalClip);
Region currentClip = Graphics.Clip;
clipStack.Push(currentClip);
aClip = aClip.Clone();
aClip.Intersect(currentClip);
Graphics.Clip = aClip;
}
示例11: DrawRegions
private void DrawRegions( Graphics g, int offset, string s, Region r1, Region r2, Region r3)
{
using (Pen p = new Pen(Color.Black))
{
using (Brush b1 = new SolidBrush(Color.Red), b2 = new SolidBrush(Color.Green), bl = new SolidBrush(Color.Blue))
{
Region region1 = r1.Clone();
Region region2 = r2.Clone();
Region region3 = r3.Clone();
int x = (offset%4) * 110;
int y = (int)offset / 4*80;
g.DrawString(s,Font, bl, x, y);
region1.Translate(x, y + 20);
region2.Translate(x, y + 20);
region3.Translate(x + 55, y + 20);
g.FillRegion(b1,region1);
g.DrawRectangle(p, Rectangle.Truncate(region1.GetBounds(g)));
g.FillRegion(b2,region2);
g.DrawRectangle(p, Rectangle.Truncate(region2.GetBounds(g)));
g.FillRegion(b1,region3);
g.DrawRectangle(p, Rectangle.Truncate(region3.GetBounds(g)));
}
}
}
示例12: MapChanged
// Called whenever the map display changes.
void MapChanged(Region regionChanged)
{
if (regionChanged == null) {
// null region means everything.
MarkAllInvalid();
}
if (allInvalid)
return; // nothing more to do.
// Copy the region and transform to bitmap coords.
Region copy = regionChanged.Clone();
copy.Transform(matTransform);
// Union with the invalid region.
if (allValid) {
allValid = false;
invalidRegion = regionChanged;
}
else
invalidRegion.Union(regionChanged);
}
示例13: MultiCombinedPathRegion
public void MultiCombinedPathRegion ()
{
// note: seems identical to PathRegion but it test another code path inside libgdiplus
Region r1 = new Region (sp1);
r1.Xor (sp2);
Region r2 = new Region (sp2);
r2.Complement (sp1);
Region r = r1.Clone ();
r.Union (r2);
RegionData data = r.GetRegionData ();
Assert.IsNotNull (data.Data, "Data");
Region region = new Region (data);
Assert.IsTrue (r.GetBounds (graphic).Equals (region.GetBounds (graphic)), "Bounds");
}
示例14: SelectInternal
// Uses the current selection positions to set what is selected in drawLayout
// Sets the update to redraw only the characters that have changed
internal override void SelectInternal(int start, int length)
{
if (start == selectionStartActual && length == selectionLengthActual)
{
return;
}
if (!IsHandleCreated)
{
return;
}
Region newRegion = new Region(RectangleF.Empty);
selectionStartActual = start;
selectionLengthActual = length;
for (int i = 0; i < Text.Length; i++)
{
bool selected = (i>=GetSelectionStart() && i < GetSelectionStart() + GetSelectionLength());
layout.Items[i].selected = selected;
Rectangle b = layout.Items[i].bounds;
b = new Rectangle(b.Left, b.Top, b.Width, b.Height + 1);
if (selected)
{
newRegion.Union(b);
}
}
// Find the region we need to redraw by Xoring with old
if (selectedRegion != null)
{
Region redrawRegion = newRegion.Clone();
redrawRegion.Xor(selectedRegion);
redrawRegion.Translate(-XViewOffset, -YViewOffset);
// Only allow updates in the TextDrawArea
redrawRegion.Intersect(new Region(TextDrawArea));
AddUpdate(redrawRegion);
}
else
{
AddUpdate(newRegion);
}
selectedRegion = newRegion;
}
示例15: PushClip
/// <summary>
/// Pushes the current clip onto the clip stack and sets clip of the graphics context to
/// the intersection of the current clip and the given clip.
/// </summary>
/// <remarks>
/// The intersection of the current local clip and the new local clip is also pushed onto
/// the local clip stack.
/// </remarks>
/// <param name="aClip">The clip to push.</param>
public virtual void PushClip(Region aClip)
{
RectangleF aClipBounds = aClip.GetBounds(graphics.Graphics);
RectangleF transformedClipBounds = Graphics.Matrix.Transform(aClipBounds);
aClip = new Region(new Rectangle((int)Math.Floor(transformedClipBounds.X),
(int)Math.Floor(transformedClipBounds.Y),
(int)Math.Ceiling(transformedClipBounds.Width),
(int)Math.Ceiling(transformedClipBounds.Height)));
// Push the untransformed clip onto the local clip stack so that it will be transformed
// when the matrix is pushed.
RectangleF newLocalClip = PUtil.IntersectionOfRectangles(LocalClip, aClipBounds);
localClipStack.Push(newLocalClip);
// Push the transformed clip onto the clip stack since the graphics objec does not
// contain a matrix and will not do the transforming itself.
Region currentClip = Graphics.Clip;
clipStack.Push(currentClip);
aClip = aClip.Clone();
aClip.Intersect(currentClip);
Graphics.Clip = aClip;
}