public IPen ToPen(float scale, PointF startPoint, PointF endPoint) { IPen pen = null; if (Marker == null) { pen = base.ToPen(scale); } else { float width = GetWidth(scale); IBrush brush = null; SizeF size = Marker.Size; int imgWidth = (int)Math.Ceiling(size.Width); int imgHeight = (int)Math.Ceiling(size.Height); Image <Rgba32> image = new Image <Rgba32>(imgWidth, imgHeight); Rectangle rectangle = new Rectangle(0, 0, imgWidth, imgHeight); float angle = DrawingHelper.GetAngle(startPoint, endPoint, true); //foreach (var symbol in Marker.Symbols) //{ // symbol.Angle += angle; //} //AffineTransformBuilder ats = new AffineTransformBuilder().AppendRotationRadians(angle, new System.Numerics.Vector2(imgWidth / 2f, imgHeight / 2f)); image.Mutate(x => { Marker.DrawLegend(x, rectangle); x.Rotate(angle); }); //foreach (var symbol in Marker.Symbols) //{ // symbol.Angle -= angle; //} brush = new ImageBrush(image); float[] dashPattern = ToDashPattern(Pattern, startPoint, endPoint); pen = new Pen(brush, width, dashPattern); } return(pen); }
public float[] ToDashPattern(float[] pattern, PointF startPoint, PointF endPoint) { float[] dashPattern = null; if (Marker == null) { dashPattern = pattern; } else { if (pattern != null) { switch (pattern.Length) { case 0: dashPattern = pattern; break; case 1: default: SizeF size = Marker.Size; int imgWidth = (int)Math.Ceiling(size.Width); int imgHeight = (int)Math.Ceiling(size.Height); switch (pattern.Length) { case 1: float angle = DrawingHelper.GetAngle(startPoint, endPoint, false); float totalLength = Convert.ToSingle(DrawingHelper.Distance(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y)); float centerX = (startPoint.X + endPoint.X) / 2; float centerY = (startPoint.Y + endPoint.Y) / 2; float dy = Convert.ToSingle(imgWidth / 2.0 * Math.Sin(angle)); float dx = Convert.ToSingle(-imgWidth / 2.0 * Math.Cos(angle)); float x = centerX - dx; float y = centerY - dy; float firstLength = Convert.ToSingle(DrawingHelper.Distance(startPoint.X, startPoint.Y, x, y)); float secondLength = imgWidth; float thirdLength = totalLength - firstLength - secondLength; if (thirdLength > 0) { dashPattern = new float[] { 0, firstLength, secondLength, thirdLength }; } break; default: dashPattern = new float[pattern.Length]; for (int i = 0; i < pattern.Length; i++) { if (i % 2 == 0) { dashPattern[i] = pattern[i] * imgWidth; } else { dashPattern[i] = pattern[i]; } float item = pattern[i]; } break; } break; } } } return(dashPattern); }