2012-08-29 1 views
0

Panel에 spirograph를 생성하기 위해 Graphics을 사용하고 있지만 BMP (또는 파일 확장명)로 도면을 저장하려고 할 때 파일은 패널의 배경 만 차지하지만 spirograph는 없습니다. 누구든지 주변을 알고 있니?C#의 spirograph ... 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(); 
    } 
+0

충분한 정보를 제공하지 않았습니다. 당신이'dessin'이라는 객체를 사용하여 그림을 그린 것처럼 보입니다. 설명이 아닌 이름을 제외하고, 나는 이것이 어떤 종류의 대상인지 모른다. –

+0

Paint 이벤트 대신 CreateGraphics() 사용할 때 발생합니다. 대신 Bitmap 및 Graphics.FromImage()를 사용하여 그 위에 그리는 것이 좋습니다. 비트 맵을 PictureBox에 표시하고 * 저장할 수 있습니다. –

답변

1

패널의 그래픽 개체에서 직접 비트 맵을 저장할 수 없습니다.

먼저 Bitmap 객체를 만들고 그로부터 Graphics를 파생시켜야합니다. 그런 다음 그림이 완성되면 비트 맵을 디스크에 저장하거나 그림 상자에 표시하거나 둘 다 원하는대로 다시 사용할 수 있습니다!

article은이를 수행하는 방법에 대한 자세한 정보를 보여줍니다.

관련 문제