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
NewPen.CreatPen(i,1,RGB(0,0,0))创建一个画笔,线宽为i,线型实线,嫌困拆颜色是黑色
MoveTo与LineTo是芹枣画线的函数
MoveTo 移动到起点尺核
LineTo 画直线到终点
pDC->SelectObject(pOldPen)//这句的意思是= =?
绘图完毕,恢复以前的画笔
提供一个绘制任意曲线的简单代码。其他功能类似,希望能举一反三。
在窗兄陵体中添加一个Picture box,然后输入命令如下:
Dim oldx As SingleDim oldy As Single
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then 饥尘慎 '当鼠标左建按下时发生
Picture1.Line (oldx, oldy)-(X, Y)
oldx = X
oldy = Y
End If
End Sub
Private Sub Picture1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As 烂敬Single)
oldx = X
oldy = Y
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)