本文整理汇总了C#中System.Drawing.Graphics.SetClip方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.SetClip方法的具体用法?C# Graphics.SetClip怎么用?C# Graphics.SetClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.SetClip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
{
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
if (applyRect.Width == 0 || applyRect.Height == 0)
{
// nothing to do
return;
}
GraphicsState state = graphics.Save();
if (Invert)
{
graphics.SetClip(applyRect);
graphics.ExcludeClip(rect);
}
ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
new[] {.3f, .3f, .3f, 0, 0},
new[] {.59f, .59f, .59f, 0, 0},
new[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
using (ImageAttributes ia = new ImageAttributes())
{
ia.SetColorMatrix(grayscaleMatrix);
graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
}
graphics.Restore(state);
}
示例2: DrawGlass
public static void DrawGlass(Rectangle rectangle, Graphics graphics)
{
if (rectangle.Width == 0 || rectangle.Height == 0)
return;
var clipPath = GetRoundedRectanglePath(rectangle);
graphics.SetClip(clipPath);
var glassRectangle = new Rectangle(rectangle.Location, new Size(rectangle.Width, rectangle.Height/2));
// Apply a glass look
Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent,
Color.FromArgb(32, 255, 255, 255), 90.0f);
var glassPath = GetRoundedRectanglePath(glassRectangle);
graphics.FillPath(glassBrush, glassPath);
glassPath.Dispose();
glassBrush.Dispose();
glassRectangle = new Rectangle(0, rectangle.Height - (rectangle.Height/4), rectangle.Width,
rectangle.Height*3);
glassPath = GetRoundedRectanglePath(glassRectangle);
glassBrush = new SolidBrush(Color.FromArgb(16, Color.White));
glassBrush.Dispose();
glassPath.Dispose();
graphics.SetClip(rectangle);
clipPath.Dispose();
}
示例3: DrawImage
public static void DrawImage(Graphics g, Image image, ImageLayoutMode layoutMode, Rectangle rect)
{
// Graphics g = Graphics.FromHwnd(IntPtr.Zero);
if (layoutMode == ImageLayoutMode.None)
{
Rectangle tempRect = new Rectangle(rect.X, rect.Y, image.Width, image.Height);
g.SetClip(rect);
g.DrawImage(image, tempRect);
g.ResetClip();
}
else if (layoutMode == ImageLayoutMode.Stretch)
{
g.DrawImage(image, rect);
}
else if (layoutMode == ImageLayoutMode.FitToWidth)
{
g.SetClip(rect);
Size newSize = new Size(rect.Width, rect.Width * image.Height / image.Width);
g.DrawImage(image, new Rectangle(rect.Location, newSize));
g.ResetClip();
}
else if (layoutMode == ImageLayoutMode.FitToHeight)
{
g.SetClip(rect);
Size newSize = new Size(rect.Height * image.Width / image.Height, rect.Height);
g.DrawImage(image, new Rectangle(rect.Location, newSize));
g.ResetClip();
}
}
示例4: Render
/// <summary>
/// Renders the specified HTML source on the specified area clipping if specified
/// </summary>
/// <param name="g">Device to draw</param>
/// <param name="html">HTML source</param>
/// <param name="area">Area where HTML should be drawn</param>
/// <param name="clip">If true, it will only paint on the specified area</param>
public static void Render(Graphics g, string html, RectangleF area, bool clip)
{
InitialContainer container = new InitialContainer(html);
Region prevClip = g.Clip;
if (clip) g.SetClip(area);
container.SetBounds(area);
container.MeasureBounds(g);
container.Paint(g);
if (clip) g.SetClip(prevClip, System.Drawing.Drawing2D.CombineMode.Replace);
}
示例5: Apply
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
{
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
if (applyRect.Width == 0 || applyRect.Height == 0)
{
// nothing to do
return;
}
int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
GraphicsState state = graphics.Save();
if (Invert)
{
graphics.SetClip(applyRect);
graphics.ExcludeClip(rect);
}
graphics.SmoothingMode = SmoothingMode.None;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.None;
int halfWidth = rect.Width / 2;
int halfHeight = rect.Height / 2;
int newWidth = rect.Width / magnificationFactor;
int newHeight = rect.Height / magnificationFactor;
Rectangle source = new Rectangle(rect.X + halfWidth - (newWidth / 2), rect.Y + halfHeight - (newHeight / 2), newWidth, newHeight);
graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel);
graphics.Restore(state);
}
示例6: Apply
/// <summary>
/// Implements the Apply code for the Brightness Filet
/// </summary>
/// <param name="graphics"></param>
/// <param name="applyBitmap"></param>
/// <param name="rect"></param>
/// <param name="renderMode"></param>
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
if (applyRect.Width == 0 || applyRect.Height == 0) {
// nothing to do
return;
}
GraphicsState state = graphics.Save();
if (Invert) {
graphics.SetClip(applyRect);
graphics.ExcludeClip(rect);
}
using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) {
Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
for (int y = fastBitmap.Top; y < fastBitmap.Bottom; y++) {
for (int x = fastBitmap.Left; x < fastBitmap.Right; x++) {
Color color = fastBitmap.GetColorAt(x, y);
color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B));
fastBitmap.SetColorAt(x, y, color);
}
}
fastBitmap.DrawTo(graphics, applyRect.Location);
}
graphics.Restore(state);
}
示例7: Draw
public void Draw(Graphics graphics)
{
graphics.SetClip(parentGraph.ClientRectangle);
Pen axisPen = new Pen(new SolidBrush(parentGraph.YAxisColor), 2F);
axisPen.EndCap = LineCap.ArrowAnchor;
RectangleF graphArea = parentGraph.GraphArea;
graphics.DrawLine(axisPen,
graphArea.Left,
graphArea.Bottom,
graphArea.Left,
graphArea.Top);
axisPen.Color = parentGraph.XAxisColor;
axisPen.EndCap = LineCap.ArrowAnchor;
graphics.DrawLine(axisPen,
graphArea.Left,
graphArea.Bottom,
graphArea.Right,
graphArea.Bottom);
axisPen.Dispose();
}
示例8: Render
/// <summary>
/// Renders the key in the specified surface.
/// </summary>
/// <param name="g">The GDI+ surface to render on.</param>
/// <param name="scrollCount">The number of times the direction has been scrolled within the timeout.</param>
public void Render(Graphics g, int scrollCount)
{
var pressed = scrollCount > 0;
var style = GlobalSettings.CurrentStyle.TryGetElementStyle<KeyStyle>(this.Id)
?? GlobalSettings.CurrentStyle.DefaultKeyStyle;
var defaultStyle = GlobalSettings.CurrentStyle.DefaultKeyStyle;
var subStyle = pressed ? style?.Pressed ?? defaultStyle.Pressed : style?.Loose ?? defaultStyle.Loose;
var text = pressed ? scrollCount.ToString() : this.Text;
var txtSize = g.MeasureString(text, subStyle.Font);
var txtPoint = new TPoint(
this.TextPosition.X - (int)(txtSize.Width / 2),
this.TextPosition.Y - (int)(txtSize.Height / 2));
// Draw the background
var backgroundBrush = this.GetBackgroundBrush(subStyle, pressed);
g.FillPolygon(backgroundBrush, this.Boundaries.ConvertAll<Point>(x => x).ToArray());
// Draw the text
g.SetClip(this.GetBoundingBox());
g.DrawString(text, subStyle.Font, new SolidBrush(subStyle.Text), (Point)txtPoint);
g.ResetClip();
// Draw the outline.
if (subStyle.ShowOutline)
g.DrawPolygon(new Pen(subStyle.Outline, 1), this.Boundaries.ConvertAll<Point>(x => x).ToArray());
}
示例9: Apply
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
{
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY);
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
if (applyRect.Width == 0 || applyRect.Height == 0)
{
return;
}
GraphicsState state = graphics.Save();
if (Invert)
{
graphics.SetClip(applyRect);
graphics.ExcludeClip(rect);
}
if (GDIplus.IsBlurPossible(blurRadius))
{
GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false);
}
else
{
using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect))
{
ImageHelper.ApplyBoxBlur(fastBitmap, blurRadius);
fastBitmap.DrawTo(graphics, applyRect);
}
}
graphics.Restore(state);
return;
}
示例10: DrawData
/// <summary>
/// Draws the data of a tree node at the specified location.</summary>
/// <param name="node">The tree control's node whose data is to be drawn</param>
/// <param name="g">The current GDI+ graphics object</param>
/// <param name="x">The x-coordinate of the upper-left corner of the node label</param>
/// <param name="y">The y-coordinate of the upper-left corner of the node label</param>
public override void DrawData(TreeControl.Node node, Graphics g, int x, int y)
{
var treeListControl = node.TreeControl as TreeListControl;
ItemInfo info = new WinFormsItemInfo();
m_itemView.GetInfo(node.Tag, info);
if (info.Properties.Length ==0)
return;
Region oldClip = g.Clip;
UpdateColumnWidths(node, info, g);
int xOffset = treeListControl.TreeWidth;
for (int i = 0; i < info.Properties.Length; ++i)
{
var dataEditor = info.Properties[i] as DataEditor;
if (dataEditor != null) // show object data details in columns
{
if (TrackingEditor != null && (TrackingEditor.Owner == node.Tag) &&
(TrackingEditor.Name == dataEditor.Name))
dataEditor = TrackingEditor;
var clip = new Rectangle(xOffset, y, treeListControl.Columns[i].ActualWidth, treeListControl.GetRowHeight(node));
if (i == info.Properties.Length-1) // extends last column
clip.Width = node.TreeControl.ActualClientSize.Width - xOffset;
g.SetClip(clip);
dataEditor.PaintValue(g, clip);
}
xOffset += treeListControl.Columns[i].ActualWidth;
}
g.Clip = oldClip;
}
示例11: RenderView
//=========================================================================================
internal void RenderView(Graphics g)
{
g.FillRectangle(SystemBrushes.Window, this.Body.ClientRectangle);
if (this.Viewer.ShowMargin)
{
this.DrawMarginBackground(g);
this.DrawLineIcons(g);
}
if (this.Viewer.ShowLineNumbers)
this.DrawLineNumbers(g);
//set the clipping region
Rectangle r = this.Body.DisplayRectangle;
r.X += this.Viewer.CharOffset - 1 + this.Viewer.MarginWidth;
g.SetClip(r);
this.DrawLinesBg(g);
if (this.Viewer.HighlightCurrentLine && this.Body.Focused)
this.DrawCurrentLineBackground(g);
this.DrawSpansBackground(g);
this.DrawSelectedTextBackground(g);
this.DrawLinesOfDocument(this.Body.DisplayRectangle.Location, g);
}
示例12: Draw
public void Draw(Graphics g)
{
g.Clear(BackgroundColor);
g.SetClip(new Rectangle(0, 0, (int)RenderWidth, (int)RenderHeight));
foreach (GDIObject obj in Objects)
{
obj.X -= CanvasX;
obj.Y -= CanvasY;
obj.Draw(g);
}
g.ResetClip();
if (ShowGrid)
{
for (var x = 0; x < RenderWidth + CanvasX; x++)
{
if (x % GridCellSize.X == 0)
g.DrawLine(GridColor, x - CanvasX, 0, x - CanvasX, RenderHeight);
}
for (var y = 0; y < RenderHeight + CanvasY; y++)
{
if (y % GridCellSize.Y == 0)
g.DrawLine(GridColor, 0, y - CanvasY, RenderWidth, y - CanvasY);
}
}
}
示例13: DrawRegionRepresentation
public override void DrawRegionRepresentation(Graphics gc, Render.RenderParameter r, Render.IDrawVisitor drawMethods, PointD mousePosition)
{
if (m_Param.Path.PointCount > 0)
{
GraphicsPath fill = new GraphicsPath();
RectangleF rect = m_Param.Path.GetBounds();
PointD refPt = (PointD)rect.Location + ((PointD)rect.Size.ToPointF()) / 2;
// this will draw beyond the shape's location
for (double i = -rect.Height; i < rect.Height; i++)
{
PointD pt1 = refPt + PointD.Orthogonal(m_Param.V) * i * drawMethods.Spacing(m_Param.C);
PointD pt2 = pt1 + m_Param.V * rect.Width * rect.Height;
PointD pt3 = pt1 - m_Param.V * rect.Width * rect.Height;
fill.StartFigure();
fill.AddLine((Point)pt2, (Point)pt3);
}
GraphicsContainer c = gc.BeginContainer();
gc.SetClip((Tools.Model.VectorPath)m_Param.Path);
gc.DrawPath(r.RegionGuides, fill);
gc.EndContainer(c);
}
}
示例14: FillRoundedRectangle
public static void FillRoundedRectangle(Rectangle rectangle, GlassGradient gradient, bool isSunk, bool isGlass,
Graphics graphics)
{
if (rectangle.Width == 0 || rectangle.Height == 0)
return;
var path = GetRoundedRectanglePath(rectangle);
var activeGradient = isSunk
? new GlassGradient(gradient.Bottom, gradient.Top)
: new GlassGradient(gradient.Top, gradient.Bottom);
var brush = activeGradient.GetBrush(rectangle);
graphics.FillPath(brush, path);
brush.Dispose();
if (isGlass)
{
graphics.SetClip(path);
var glassRectangle = isSunk
? new Rectangle(new Point(rectangle.Left, rectangle.Height/2),
new Size(rectangle.Width, rectangle.Height/2))
: new Rectangle(rectangle.Location,
new Size(rectangle.Width, rectangle.Height/2));
var glassPath = GetRoundedRectanglePath(glassRectangle);
Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent,
Color.FromArgb(32, 255, 255, 255), 90.0f);
graphics.FillPath(glassBrush, glassPath);
glassBrush.Dispose();
glassPath.Dispose();
}
}
示例15: Paint
/// <summary>
/// Renders rectangle on canvas.
/// </summary>
/// <param name="g">Target graphics to render shape on.</param>
/// <param name="bounds">Shape bounds.</param>
public override void Paint(Graphics g, Rectangle bounds)
{
if (bounds.Width < 2 || bounds.Height < 2 || g == null || _Fill == null && _Border == null) return;
GraphicsPath path = null;
if (!_CornerRadius.IsZero)
{
path = DisplayHelp.GetRoundedRectanglePath(bounds, _CornerRadius.TopLeft, _CornerRadius.TopRight,
_CornerRadius.BottomRight, _CornerRadius.BottomLeft);
}
if (_Fill != null)
{
Brush brush = _Fill.CreateBrush(bounds);
if (brush != null)
{
SmoothingMode sm = g.SmoothingMode;
if (brush is SolidBrush && path==null)
g.SmoothingMode = SmoothingMode.None;
if (path == null)
g.FillRectangle(brush, bounds);
else
g.FillPath(brush, path);
g.SmoothingMode = sm;
brush.Dispose();
}
}
if (_Border != null)
{
Pen pen = _Border.CreatePen();
if (pen != null)
{
if (path == null)
g.DrawRectangle(pen, bounds);
else
g.DrawPath(pen, path);
pen.Dispose();
}
}
Shape content = this.Content;
if (content != null)
{
Rectangle contentBounds = Border.Deflate(bounds, _Border);
Region oldClip = null;
if (path != null && ClipToBounds)
{
oldClip = g.Clip;
g.SetClip(path, CombineMode.Intersect);
}
content.Paint(g, contentBounds);
if (oldClip != null) g.Clip = oldClip;
}
if (path != null) path.Dispose();
}