日期:2014-05-18  浏览次数:20980 次

怎么绘制一个圆形啊
有没有用C#写的绘制一个圆的算法啊~
或者资料
谢谢啦就还有100分了。。都给您

------解决方案--------------------
对于程序员,任何可以用语言、表达式描述的算法,都可以变成程序。这是基本功。

没有所谓“会不会”的。只有北大菜鸟copy一族才见到代码心才落地。

你说不想写说对了。为你付出精力本身已经不值得,再说这个需求GDI/GDI+都有实现,本身也没有什么让人想自己再写一遍的动力。
------解决方案--------------------
你要的是不是这样的:
wpf例子,gdi+也差不多
[code=c#]
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      //this.VisualEdgeMode = EdgeMode.Aliased;
      CustomDrawing cd = new CustomDrawing(100, 100, 80);
      canvas1.Children.Add(cd);
    }
  }
  class CustomDrawing : UIElement
  {
    VisualCollection childs;
    public CustomDrawing(double centerx, double centery, double radius)
    {
      childs = new VisualCollection(this);
      DrawingVisual dv = new DrawingVisual();
      Pen p = new Pen(Brushes.Black,1);
      p.Freeze();
      int points = (int)(radius * 2);
      double per = 2 * Math.PI / points;
      using (DrawingContext dc = dv.RenderOpen())
      {
        for (int i = 0; i < points; i++)
        {
          dc.DrawLine(p,
            new Point(radius * Math.Cos(per * i) + centerx, radius * Math.Sin(per * i) + centery),
            new Point(radius * Math.Cos(per * (i + 1)) + centerx, radius * Math.Sin(per * (i + 1)) + centery));
        }
      }
      childs.Add(dv);
    }
    protected override int VisualChildrenCount
    {
      get { return childs.Count; }
    }
    protected override Visual GetVisualChild(int index)
    {
      if (index < 0 || index >= childs.Count)
      {
        throw new ArgumentOutOfRangeException();
      }
      return childs[index];
    }
  }
[/code]
不过这种做法得不偿失,还是直接调用api不但省事而且程序效率高。除非用directx这样的东西画圆才有必要自己计算顶点。