0
我在Panel
上使用Graphics
來生成Spirograph,但是當我嘗試將繪圖保存爲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();
}
您尚未提供足夠的信息。看起來您正在使用名爲「dessin」的對象進行繪製。除了非描述性的名字,我不知道這是什麼類型的對象。 –
當您使用CreateGraphics()而不是Paint事件時會發生這種情況。相反,考慮創建一個位圖和Graphics.FromImage()來繪製它。您可以在PictureBox *中顯示位圖並將其保存。 –