public MaskedSurface(Surface source, PdnGraphicsPath path) { RectangleF boundsF = path.GetBounds(); Rectangle bounds = Utility.RoundRectangle(boundsF); Rectangle boundsClipped = Rectangle.Intersect(bounds, source.Bounds); Rectangle boundsRead; if (bounds != boundsClipped) { PdnRegion region = new PdnRegion(path); region.Intersect(source.Bounds); SetPathField(PdnGraphicsPath.FromRegion(region)); this.region = region; boundsRead = region.GetBoundsInt(); } else { SetPathField(path.Clone()); this.region = new PdnRegion(this.path); boundsRead = boundsClipped; } if (boundsRead.Width > 0 && boundsRead.Height > 0) { this.surface = new Surface(boundsRead.Size); this.surface.CopySurface(source, boundsRead); } else { this.surface = null; } }
/// <summary> /// Constructs an IrregularSurface by copying the given region-of-interest from an Image. /// </summary> /// <param name="source">The Surface to copy pixels from.</param> /// <param name="roi">Defines the Region from which to copy pixels from the Image.</param> public IrregularSurface(Surface source, PdnRegion roi) { PdnRegion roiClipped = (PdnRegion)roi.Clone(); roiClipped.Intersect(source.Bounds); Rectangle[] rects = roiClipped.GetRegionScansReadOnlyInt(); this.placedSurfaces = new ArrayList(rects.Length); foreach (Rectangle rect in rects) { this.placedSurfaces.Add(new PlacedSurface(source, rect)); } this.region = roiClipped; }
public PdnRegion CreateRegion() { lock (this.syncRoot) { if (IsEmpty) { return(new PdnRegion(this.clipRectangle)); } else { PdnRegion region = CreateRegionRaw(); region.Intersect(this.clipRectangle); return(region); } } }
protected override void OnPaint(PaintEventArgs e) { if (this.surface != null) { PdnRegion clipRegion = null; Rectangle[] rects = this.realUpdateRects; if (rects == null) { clipRegion = new PdnRegion(e.Graphics.Clip, true); clipRegion.Intersect(e.ClipRectangle); rects = clipRegion.GetRegionScansReadOnlyInt(); } if (this.justPaintWhite > 0) { PdnGraphics.FillRectangles(e.Graphics, Color.White, rects); } else { foreach (Rectangle rect in rects) { if (e.Graphics.IsVisible(rect)) { PaintEventArgs2 e2 = new PaintEventArgs2(e.Graphics, rect); OnPaintImpl(e2); } } } if (clipRegion != null) { clipRegion.Dispose(); clipRegion = null; } } if (this.justPaintWhite > 0) { --this.justPaintWhite; } base.OnPaint(e); }
/// <summary> /// Constructs a MaskSurface by copying the given region-of-interest from an Image. /// </summary> /// <param name="source">The Surface to copy pixels from.</param> /// <param name="roi">Defines the Region from which to copy pixels from the Image.</param> public MaskedSurface(Surface source, PdnRegion roi) { PdnRegion roiClipped = (PdnRegion)roi.Clone(); roiClipped.Intersect(source.Bounds); Rectangle boundsClipped = roiClipped.GetBoundsInt(); this.surface = new Surface(boundsClipped.Size); this.surface.Clear(ColorBgra.FromUInt32(0x00ffffff)); Rectangle rect = boundsClipped; Point dstOffset = new Point(rect.X - boundsClipped.X, rect.Y - boundsClipped.Y); this.surface.CopySurface(source, dstOffset, rect); this.region = roiClipped; // TODO: FromRegion() is a VERY expensive call for what we are doing! PdnGraphicsPath newPath = PdnGraphicsPath.FromRegion(this.region); SetPathField(newPath); }