2013-06-26 70 views
1

我需要通过C#图形绘制Google标记图像 为那个我需要Google标记的确切坐标 我该怎么做请帮忙。 我的当前代码是。需要通过C#图形绘制Google标记图像

private void Shape8(PaintEventArgs e) 
     { 
      e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; 

      int startMarker = 0; 
      int MarkerDiameter = 30; 
      int EllipseDiameter = 15; 

      const int StartX = 150; 
      const int StartY = 350; 

      int X = StartX; 
      int Y = StartY; 

      GraphicsPath path = new GraphicsPath(); 
      Rectangle ellipse = new Rectangle(X, Y, EllipseDiameter, EllipseDiameter); 
      path.AddEllipse(ellipse); 
      path.CloseFigure(); 

      X = X + (EllipseDiameter/2) - (MarkerDiameter/2); 
      Y = Y - (EllipseDiameter * 2) - (MarkerDiameter/2); 

      startMarker = StartY - 10 - (Convert.ToInt32(MarkerDiameter * 1.5));//Space Between marker and circle. 
      AddMarker8(ref path, X, startMarker, StartX, StartY, EllipseDiameter, MarkerDiameter, "Concept1"); 

      e.Graphics.FillPath(Brushes.Pink, path); 
      e.Graphics.DrawPath(Pens.Black, path); 
      e.Graphics.FillEllipse(Brushes.White, ellipse); 

      path.CloseAllFigures(); 

     } 

private void AddMarker8(ref GraphicsPath path, int X, int Y, int StartX, int StartY, int EllipseDiameter, int MarkerDiameter, string conceptName) 
     { 
      float startAngle = 180.0F; 
      float sweepAngle = 180.0F; 
      int fontStyle = (int)FontStyle.Regular; 

      path.AddString(conceptName, new FontFamily("Arial"), fontStyle, 15, new Point(X + (MarkerDiameter/2), Y - 15), lblFormat); 
      Rectangle rect = new Rectangle(X, Y, MarkerDiameter, MarkerDiameter); 
      path.AddArc(rect, startAngle, sweepAngle); 

      Point lastpoint = new Point(X + (MarkerDiameter/2), (Y + (MarkerDiameter * 2)) - (MarkerDiameter/2)); 
      path.AddCurve(new Point[] { 
       new Point(X+(MarkerDiameter), Y + (MarkerDiameter/2)), //a 
       new Point((X +MarkerDiameter)-(MarkerDiameter/4) ,(Y +(MarkerDiameter))) ,//A.5 
       lastpoint ,//c 
       new Point(X +(MarkerDiameter/4) ,(Y +(MarkerDiameter))) ,//B.5 
       new Point(X, Y + (MarkerDiameter/2))//b 
        }, 0.5f); 

      path.CloseFigure(); 
     } 
+0

当你说“谷歌标志的精确坐标”,你的意思确切的形状? –

+0

是的,我也需要重新调整大小。 – Arry

回答

0

试试下面的代码

private void DrawMarker(int X, int Y, double Scale, Color BorderColor, Color FillColor, PaintEventArgs e, char Letter = '\0') 
    { 
     Graphics G1 = e.Graphics; 
     Pen Pen1 = new Pen(BorderColor, 8); 
     SolidBrush Brush1 = new SolidBrush(BorderColor); 
     SolidBrush Brush2 = new SolidBrush(FillColor); 

     G1.SmoothingMode = SmoothingMode.AntiAlias; 
     G1.ResetTransform(); 
     G1.ScaleTransform(Convert.ToSingle(0.4 * Scale), Convert.ToSingle(0.4 * Scale)); 

     GraphicsPath GraphicsPath1 = new GraphicsPath(); 
     GraphicsPath1.AddBeziers(new Point(X + 51, Y + 169), new Point(X + 47, Y + 137), new Point(X + 42, Y + 107), new Point(X + 14, Y + 77)); 
     GraphicsPath1.AddBeziers(new Point(X + 87, Y + 77), new Point(X + 62, Y + 107), new Point(X + 55, Y + 137), new Point(X + 51, Y + 169)); 

     GraphicsPath GraphicsPath2 = new GraphicsPath(); 
     GraphicsPath2.AddEllipse(X + 5, Y + 5, 92, 92); 
     G1.FillPath(Brush2, GraphicsPath2); 
     G1.DrawPath(Pen1, GraphicsPath2); 
     G1.SetClip(new Rectangle(X, Y + 85, 103, 84)); 
     G1.FillPath(Brush2, GraphicsPath1); 
     G1.DrawPath(Pen1, GraphicsPath1); 
     G1.ResetClip(); 

     if (Letter != '\0') 
     { 
      Font Font1 = new Font("Arial", 52, FontStyle.Bold); 
      StringFormat StringFormat1 = new StringFormat 
      { 
       Alignment = StringAlignment.Center, 
       LineAlignment = StringAlignment.Center 
      }; 

      G1.DrawString(Convert.ToString(Letter), Font1, Brush1, new Rectangle(X, Y, 103, 103), StringFormat1); 

      Font1.Dispose(); 
      StringFormat1.Dispose(); 
     } 
     else 
     { 
      G1.FillEllipse(Brush1, new Rectangle(X + 32, Y + 32, 37, 37)); 
     } 

     Pen1.Dispose(); 
     Brush1.Dispose(); 
     Brush2.Dispose(); 
     GraphicsPath1.Dispose(); 
     GraphicsPath2.Dispose(); 
    } 

    private void Form1_Paint(object sender, PaintEventArgs e) 
    { 
     DrawMarker(0, 0, 0.5, Color.Black, Color.Tomato, e, Convert.ToChar("A")); 
     DrawMarker(80, 0, 0.8, Color.Black, Color.Red, e, Convert.ToChar("B")); 
     DrawMarker(160, 0, 1, Color.Black, Color.Linen, e, Convert.ToChar("C")); 
     DrawMarker(210, 0, 1.3, Color.Black, Color.Orange, e, Convert.ToChar("D")); 
     DrawMarker(260, 0, 1.6, Color.Black, Color.Green, e); 
    } 

它运行后,其结果应该是这样的

enter image description here