C# 简易的绘图程序 求代码 类似于Windows的画图程序,能够画点、直线、矩形、椭圆等几何形状.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 00:44:07
C# 简易的绘图程序 求代码 类似于Windows的画图程序,能够画点、直线、矩形、椭圆等几何形状.
C# 简易的绘图程序 求代码 类似于Windows的画图程序,能够画点、直线、矩形、椭圆等几何形状.
C# 简易的绘图程序 求代码 类似于Windows的画图程序,能够画点、直线、矩形、椭圆等几何形状.
Bitmap NewBmp = new Bitmap(w, h);//定义画布
Graphics g = Graphics.FromImage(NewBmp); //定义画笔
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.TranslateTransform(w * bottom, h * top);
g.ScaleTransform((top - bottom) * w / PointNum, -(top - bottom) * h / MaxCoordinate); //坐标转换,这里的top,bottom是picturepanel的尺寸
Pen pen = new Pen(Color.Blue, 0.5f);
Pen pennew = new Pen(Color.Black, 0.5f);
float i = 0;
for (int p = 0; p < 6; p++)
{
i = PointNum * p / HGridNum;
g.DrawLine(pennew, i, 0, i, MaxCoordinate);
}
i = 0;
for (int q = 0; q < 11; q++)
{
g.DrawLine(pennew, 0, i, PointNum, i);
i = MaxCoordinate * (q + 1) / WGridNum;
}
for (int p = 0; p < PointNum - 1; p++) //画曲线
{
g.DrawLine(pen, p, Point[p], (p + 1), Point[p + 1]);
}
g.Dispose();
g = Graphics.FromImage(NewBmp);
g.TranslateTransform(0, h);
float[] PointY = Getycoordinate(MaxCoordinate); //画Y轴坐标
Font font = new Font("Arial", 9, FontStyle.Italic);
Pen pn = new Pen(Color.Red);
float m = w / 20, s = h / 10;
for (int j = 0; j < 11; j++)
{
//g.DrawString(Convert.ToString(ysign[j]), font, pn.Brush, m, -s);
g.DrawString(Convert.ToString(PointY[j]), font, pn.Brush, m, -s);
s += h * 8 / 100.0f;
}
int[] PointX = Getxcoordinate(PointNum);
float x = w / 10, y = h / 20;
for (int k = 0; k < 11; k++)
{
g.DrawString(Convert.ToString(PointX[k]), font, pn.Brush, x, -y);
x += w * 8 / 100f;
} //drawstring是画的坐标值
//g.DrawString(strEnd, font, Brushes.Red, _w * 17 / 20f, -_h / 20f);
//g.DrawString(str, font, Brushes.Red, _w / 10f, -_h / 20f);
g.Dispose();
this.panelPicture.BackgroundImage = DrawCurve(panelPicture.Width, this.Size.Height); //将画布赋给panelpicture