本文整理汇总了C#中System.Windows.Media.GeometryDrawing类的典型用法代码示例。如果您正苦于以下问题:C# GeometryDrawing类的具体用法?C# GeometryDrawing怎么用?C# GeometryDrawing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeometryDrawing类属于System.Windows.Media命名空间,在下文中一共展示了GeometryDrawing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAndAddAdornment
void CreateAndAddAdornment(ITextViewLine line, SnapshotSpan span, Brush brush, bool extendToRight)
{
var markerGeometry = _view.TextViewLines.GetMarkerGeometry(span);
double left = 0;
double width = _view.ViewportWidth + _view.MaxTextRightCoordinate;
if (markerGeometry != null)
{
left = markerGeometry.Bounds.Left;
if (!extendToRight) width = markerGeometry.Bounds.Width;
}
Rect rect = new Rect(left, line.Top, width, line.Height);
RectangleGeometry geometry = new RectangleGeometry(rect);
GeometryDrawing drawing = new GeometryDrawing(brush, new Pen(), geometry);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
示例2: DrawCore
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
if (drawingContext == null)
{
throw new ArgumentNullException("drawingContext");
}
if (null == drawingAttributes)
{
throw new ArgumentNullException("drawingAttributes");
}
Pen pen = new Pen
{
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round,
Brush = new SolidColorBrush(drawingAttributes.Color),
Thickness = drawingAttributes.Width
};
BrushConverter bc = new BrushConverter();
Brush BackGround = (Brush)bc.ConvertFromString(drawingAttributes.GetPropertyData(DrawAttributesGuid.BackgroundColor).ToString());
GeometryConverter gc = new GeometryConverter();
Geometry geometry = (Geometry)gc.ConvertFromString(string.Format("M {0},{1} {2},{3} {4},{5} Z", StylusPoints[0].X, StylusPoints[1].Y, (Math.Abs(StylusPoints[1].X - StylusPoints[0].X))/2 + StylusPoints[0].X, StylusPoints[0].Y, StylusPoints[1].X, StylusPoints[1].Y));
GeometryDrawing gd = new GeometryDrawing(BackGround, pen, geometry);
drawingContext.DrawDrawing(gd);
}
示例3: CreateArcDrawing
/// <summary>
/// Create an Arc geometry drawing of an ellipse or circle
/// </summary>
/// <param name="rect">Box to hold the whole ellipse described by the arc</param>
/// <param name="startDegrees">Start angle of the arc degrees within the ellipse. 0 degrees is a line to the right.</param>
/// <param name="sweepDegrees">Sweep angle, -ve = Counterclockwise, +ve = Clockwise</param>
/// <returns>GeometryDrawing object</returns>
private static GeometryDrawing CreateArcDrawing(Rect rect, double startDegrees, double sweepDegrees)
{
// degrees to radians conversion
double startRadians = startDegrees * Math.PI / 180.0;
double sweepRadians = sweepDegrees * Math.PI / 180.0;
// x and y radius
double dx = rect.Width / 2;
double dy = rect.Height / 2;
// determine the start point
double xs = rect.X + dx + (Math.Cos(startRadians) * dx);
double ys = rect.Y + dy + (Math.Sin(startRadians) * dy);
// determine the end point
double xe = rect.X + dx + (Math.Cos(startRadians + sweepRadians) * dx);
double ye = rect.Y + dy + (Math.Sin(startRadians + sweepRadians) * dy);
// draw the arc into a stream geometry
StreamGeometry streamGeom = new StreamGeometry();
using (StreamGeometryContext ctx = streamGeom.Open())
{
bool isLargeArc = Math.Abs(sweepDegrees) > 180;
SweepDirection sweepDirection = sweepDegrees < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
ctx.BeginFigure(new Point(xs, ys), false, false);
ctx.ArcTo(new Point(xe, ye), new Size(dx, dy), 0, isLargeArc, sweepDirection, true, false);
}
// create the drawing
GeometryDrawing drawing = new GeometryDrawing();
drawing.Geometry = streamGeom;
return drawing;
}
示例4: CreateErrorPen
public static Pen CreateErrorPen(Color color)
{
var geometry = new StreamGeometry();
using (var context = geometry.Open())
{
context.BeginFigure(new Point(-1, 0), false, false);
context.PolyLineTo(new[] {
new Point(-0.5, 0.4),
new Point(0, 0),
new Point(0.5, -0.4),
new Point(1, 0),
}, true, true);
}
var brushPattern = new GeometryDrawing
{
Pen = new Pen(new SolidColorBrush(color), 0.4),
Geometry = geometry
};
var brush = new DrawingBrush(brushPattern)
{
TileMode = TileMode.Tile,
Viewport = new Rect(-1, -1, 2, 2),
ViewportUnits = BrushMappingMode.Absolute,
Viewbox = new Rect(-1, -1, 2, 2),
ViewboxUnits = BrushMappingMode.Absolute,
};
var pen = new Pen(brush, 3.0);
pen.Freeze();
return pen;
}
示例5: CreateARectangleWithDrawingBrush
private Brush CreateARectangleWithDrawingBrush()
{
// Create a DrawingBrush
DrawingBrush blackBrush = new DrawingBrush();
// Create a Geometry with white background
GeometryDrawing backgroundSquare =
new GeometryDrawing(
Brushes.DarkGray,
null,
new RectangleGeometry(new Rect(0, 0, 400, 400)));
// Create a GeometryGroup that will be added to Geometry
GeometryGroup gGroup = new GeometryGroup();
gGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 200, 200)));
gGroup.Children.Add(new RectangleGeometry(new Rect(200, 200, 200, 200)));
// Create a GeomertyDrawing
GeometryDrawing checkers = new GeometryDrawing(new SolidColorBrush(Colors.Gray), null, gGroup);
DrawingGroup checkersDrawingGroup = new DrawingGroup();
checkersDrawingGroup.Children.Add(backgroundSquare);
checkersDrawingGroup.Children.Add(checkers);
blackBrush.Drawing = checkersDrawingGroup;
// Set Viewport and TimeMode
blackBrush.Viewport = new Rect(0, 0, 0.1, 0.2);
blackBrush.TileMode = TileMode.Tile;
return blackBrush;
}
示例6: createDrawingWithFrameRectangleGeometry
private Drawing createDrawingWithFrameRectangleGeometry()
{
GeometryDrawing drawing = new GeometryDrawing();
drawing.Pen = new Pen(Brushes.Black, 1);
drawing.Geometry = buildFrameRectangle();
return drawing;
}
示例7: MainWindow
public MainWindow()
{
InitializeComponent();
drawingGroup = new DrawingGroup();
// Создаем объект для описания геометрической фигуры
GeometryDrawing geometryDrawing = new GeometryDrawing();
// Описываем и сохраняем геометрию квадрата
RectangleGeometry rectGeometry = new RectangleGeometry();
rectGeometry.Rect = new Rect(0, 0, 10, 10);
geometryDrawing.Geometry = rectGeometry;
// Настраиваем перо и кисть
geometryDrawing.Pen = new Pen(Brushes.Red, 0.005);// Перо рамки
geometryDrawing.Brush = Brushes.LightBlue;// Кисть закраски
// Добавляем готовый слой в контейнер отображения
drawingGroup.Children.Add(geometryDrawing);
GeometryDrawing ellipsgeomy = new GeometryDrawing();
EllipseGeometry elgeometry = new EllipseGeometry(new Point(5, 5), 2, 2);
ellipsgeomy.Geometry = elgeometry;
ellipsgeomy.Brush = Brushes.White;
drawingGroup.Children.Add(ellipsgeomy);
}
示例8: SetFillBrush
public void SetFillBrush()
{
DrawingGroup rootDrawingGroup = new DrawingGroup();
GeometryDrawing aDrawing = new GeometryDrawing();
aDrawing.Brush = Brushes.Gray.CloneCurrentValue();
aDrawing.Pen = new Pen(Brushes.Gray, 1);
aDrawing.Brush.Opacity = .5;
aDrawing.Geometry = Primitives.PolygonLine(WallElementDetails.StartPoint, WallElementDetails.EndPoint, 10, 10);
rootDrawingGroup.Children.Add(aDrawing);
//create a transition line
GeometryDrawing aCenterLine = new GeometryDrawing();
aCenterLine.Brush = Brushs.WallBoundaryStroke;
aCenterLine.Pen = Pens.WallBoundaryStroke;
aCenterLine.Geometry = Primitives.Line(WallElementDetails.StartPoint, WallElementDetails.EndPoint);
rootDrawingGroup.Children.Add(aCenterLine);
DrawingBrush brush = new DrawingBrush(rootDrawingGroup);
this.Fill = brush;
}
示例9: AreaSeries2D
public AreaSeries2D()
{
// 初始化保存数据点的变量
_points = new SeriesPointCollection();
_points.CollectionChanged += _points_CollectionChanged;
// 初始化绘制曲线的画板
gStream_Line = new StreamGeometry();
gStream_Area = new StreamGeometry();
gDrawing_Line = new GeometryDrawing();
gDrawing_Line.Brush = null;
gDrawing_Line.Pen = new Pen()
{
Thickness = 1,
Brush = Brushes.Black
};
gDrawing_Line.Geometry = gStream_Line;
/* 初始化绘制填充色的画板 */
gDrawing_Area = new GeometryDrawing();
gDrawing_Area.Brush = Brushes.Red;
gDrawing_Area.Pen = new Pen()
{
Thickness = 0,
Brush = null
};
gDrawing_Area.Geometry = gStream_Area;
/* 生成绘画组 */
drawingGroup = new DrawingGroup();
drawingGroup.Children.Add(gDrawing_Line);
drawingGroup.Children.Add(gDrawing_Area);
}
示例10: OnRender
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
{
base.OnRender(drawingContext);
// allows the points to be rendered as an image that can be further manipulated
PathGeometry geometry = new PathGeometry();
this.Siz
// Add all points to the geometry
foreach (Points pointXY in _points)
{
PathFigure figure = new PathFigure();
figure.StartPoint = pointXY.FromPoint;
figure.Segments.Add(new LineSegment(pointXY.ToPoint, true));
geometry.Figures.Add(figure);
}
// Add the first point to close the gap from the graph's end point
// to graph's start point
PathFigure lastFigure = new PathFigure();
lastFigure.StartPoint = _points[_points.Count - 1].FromPoint;
lastFigure.Segments.Add(new LineSegment(_firstPoint, true));
geometry.Figures.Add(lastFigure);
// Create a new drawing and drawing group in order to apply
// a custom drawing effect
GeometryDrawing drawing = new GeometryDrawing(this.Pen.Brush, this.Pen, geometry);
DrawingGroup drawingGroup = new DrawingGroup();
drawingGroup.Children.Add(drawing);
}
示例11: createDrawingWithGroupGemoetry
private Drawing createDrawingWithGroupGemoetry()
{
GeometryDrawing drawing = new GeometryDrawing();
drawing.Pen = new Pen(Brushes.Black, 1);
drawing.Geometry = buildGeometryGroup();
return drawing;
}
示例12: Init
public void Init()
{
DrawingGroup dg = new DrawingGroup();
ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight));
dg.Children.Add(id);
pointsGeometryGroup = new GeometryGroup();
linesGeometryGroup = new GeometryGroup();
middlePointGeoGrp = new GeometryGroup();
if (points != null)
{
SetPointsGeometry();
}
GeometryDrawing gd = new GeometryDrawing(Brushes.Blue, null, pointsGeometryGroup);
dg.Children.Add(gd);
GeometryDrawing gd2 = new GeometryDrawing(null, new Pen(Brushes.LightGreen,3), linesGeometryGroup);
dg.Children.Add(gd2);
GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp);
dg.Children.Add(gd1);
Brush b = new SolidColorBrush(Colors.Red);
b.Opacity = 0.5;
mousePointGeometryDrwaing = new GeometryDrawing(b, null, null);
dg.Children.Add(mousePointGeometryDrwaing);
DrawingImage di = new DrawingImage(dg);
this.Source = di;
chosenPoint = -1;
}
示例13: PaintBackground
private void PaintBackground()
{
var backgroundSquare = new GeometryDrawing(Brushes.Black, null, new RectangleGeometry(new Rect(0, 0, 100, 100)));
var aGeometryGroup = new GeometryGroup();
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50)));
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50)));
var checkerBrush = new LinearGradientBrush();
checkerBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));
checkerBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 22, 0), 1.0));
var checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup);
var checkersDrawingGroup = new DrawingGroup();
checkersDrawingGroup.Children.Add(backgroundSquare);
checkersDrawingGroup.Children.Add(checkers);
var myBrush = new DrawingBrush
{
Drawing = checkersDrawingGroup,
Viewport = new Rect(0, 0, 0.02, 0.02),
TileMode = TileMode.Tile,
Opacity = 0.5
};
LayoutRoot.Background = myBrush;
}
示例14: AShape
/// <summary>
/// Create a new abstract shape.
/// </summary>
/// <param name="Id">The Id of the shape.</param>
/// <param name="Latitude">The latitude of the shape center.</param>
/// <param name="Longitude">The longitude of the shape center.</param>
/// <param name="Altitude">The altitude of the shape center.</param>
/// <param name="GeoWidth">The geographical width of the shape center.</param>
/// <param name="GeoHeight">The geographical height of the shape center.</param>
public AShape(String[] Geometries, Latitude Latitude, Longitude Longitude, Altitude Altitude, Latitude Latitude2, Longitude Longitude2, Color StrokeColor, Double StrokeThickness, Color FillColor)
{
this.Id = Id;
this.Latitude = Latitude;
this.Longitude = Longitude;
this.Altitude = Altitude;
this.Latitude2 = Latitude2;
this.Longitude2 = Longitude2;
var PathGeometry16 = PathGeometry.Parse(Geometries[8]);
var GD16 = new GeometryDrawing(new SolidColorBrush(FillColor), new Pen(new SolidColorBrush(StrokeColor), StrokeThickness), PathGeometry16);
var DrawingGroup = new DrawingGroup();
DrawingGroup.Children.Add(GD16);
this.Fill = new DrawingBrush()
{
Drawing = DrawingGroup,
//Viewport = new Rect(0, 0, 1, 1),
TileMode = TileMode.None,
Stretch = Stretch.UniformToFill
};
Bounds = DrawingGroup.Bounds;
var w = Bounds.Width;
var h = Bounds.Height;
}
示例15: CreateVisuals
/// <summary>
/// Within the given line add the scarlet box behind the a
/// </summary>
private void CreateVisuals(ITextViewLine line)
{
//grab a reference to the lines in the current TextView
IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
int start = line.Start;
int end = line.End;
//Loop through each character, and place a box around any a
for (int i = start; (i < end); ++i)
{
if (_view.TextSnapshot[i] == 'a')
{
SnapshotSpan span = new SnapshotSpan(_view.TextSnapshot, Span.FromBounds(i, i + 1));
Geometry g = textViewLines.GetMarkerGeometry(span);
if (g != null)
{
GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
//Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
}
}
}