0

我正在使用GraphicsaPanel来生成螺旋图,但是当我尝试将绘图另存为 BMP(或任何文件扩展名)时,该文件仅采用面板的背景,但螺旋图不存在!有谁知道周围的方法?

        int rayonA = Convert.ToInt32(txtCercleFixe.Text);
        int rayonB = Convert.ToInt32(txtCercleNonFixe.Text);
        int distance = Convert.ToInt32(txtPenDistance.Text);
        int pointsParCourbe = Convert.ToInt32(txtPointsParCourbe.Text);
        int TypeCourbe = 0;


        Graphics dessin = pnlSpiro.CreateGraphics();

public void DessinHypotrochoid(ref Graphics dessin, PointF ptOrigin, int rayonA, int rayonB, int distance, int pointParCourbe, int PFC, int rouge, int vert, int bleu,bool random)
    {
        // Dim angleStep As Double = radiansPerCircle / PointsPerCurve
        double angleStep = radians / pointParCourbe;

        //' Compute number of revolutions.
        //Dim NumRevolutions As Integer = (bRadius / HighestCommonFactor(Math.Round(aRadius), Math.Round(bRadius)))
        int NumRevolution = rayonB / PFC;

        //' Total number of points to generate
        //Nombre de points totaux à générer
        //Dim NumPoints As Integer = PointsPerCurve * NumRevolutions
        int NumPoints = pointParCourbe * NumRevolution;

        //Dim oldPoint As New PointF( _
        // ptOrigin.X + aRadius - bRadius + distance, ptOrigin.Y)
        PointF oldPoint = new PointF((ptOrigin.X + rayonA - rayonB + distance), ptOrigin.Y);

        //Dim angle As Double = 0
        double angle = 0;
        //Dim aMinusb As Double = aRadius - bRadius
        double aMoinsB = rayonA - rayonB;
        //Dim aMinusbOverb As Double = aMinusb / bRadius
        double aDiviseB = aMoinsB / rayonB;
        //Dim pt As Integer
        //For pt = 0 To NumPoints - 1
        // On fait le dessin.

        for (int pt = 0; pt <= NumPoints; pt += 1)
        {
            angle += angleStep;
            PointF newPoint = new PointF((float)(ptOrigin.X + aMoinsB * Math.Cos(angle) + distance * Math.Cos(angle * aDiviseB)),(float)(ptOrigin.Y + aMoinsB * Math.Sin(angle) - distance * Math.Sin(angle * aDiviseB)));
            if (pt == 0)
            {
                oldPoint = newPoint;
            }
            if (random == false)
            {
                Pen Pinceau = new Pen(Color.FromArgb(rouge, vert, bleu), 1);
                dessin.DrawLine(Pinceau, oldPoint, newPoint);
            }
            else
            {
                Random r = new Random();
                Pen Pinceau = new Pen(Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256)), 1);
                dessin.DrawLine(Pinceau, oldPoint, newPoint);
            }

            oldPoint = newPoint;
        }
        dessin.Flush();
        dessin.Dispose();
    }
4

1 回答 1

1

您不能直接从 Panel 的 Graphics 对象保存位图。

首先,您必须创建一个 Bitmap 对象并从中派生 Graphics。然后,一旦绘图完成,您可以根据需要重新使用位图:将其保存到磁盘或显示在图片框中,或两者兼而有之!

本文将向您展示有关如何执行此操作的详细信息

于 2012-08-29T14:06:43.130 回答