vb中如何在picturebox中写点的代码?然后把像素值赋给各点,显示出整个图像。是不是需要建立坐标系?
2个回答
展开全部
’给你一个简单的例子,新建工程后在窗体上插入一个picture1的控件,和一个command1的控件
‘例子中可以显示坐标系,如不需要显示删除那一段代码即可
Private Sub Command1_Click()
'绘制f(x)=8*sin(x)正弦波
Picture1.DrawWidth = 2 '设置绘图线宽(点大小)
Dim y As Double
For x = -12 To 12 Step 0.01
y = 8 * Sin(x)
Picture1.PSet (x, y), vbRed '按点绘图,颜色为红色
Next
End Sub
Private Sub Form_Load()
Command1.Caption = "绘图"
Command1.Height = 380
Command1.ToolTipText = "绘制f(x)=8*sin(x)正弦波"
Picture1.AutoRedraw = True
End Sub
Private Sub Form_Resize()
'调整图片框位置与大小
On Error Resume Next
Picture1.DrawWidth = 1
Command1.Top = Me.ScaleHeight - Command1.Height - 100
Command1.Left = Me.ScaleWidth / 2 - Command1.Width / 2
Picture1.Cls
Picture1.Width = Me.ScaleWidth - 20
Picture1.Height = Me.ScaleHeight - 700
Picture1.Move 0, 100
'建立坐标系
Picture1.Scale (-12, 12)-(12, -12) '设置picture坐标从左上角的(X,Y)到右下角的(X,Y)的坐标
'显示坐标
Picture1.Line (-12, 0)-(12, 0)
Picture1.Line (0, 12)-(0, -12)
For i = -12 To 12
Picture1.Line (i, 0)-(i, -0.5)
Picture1.Print i
Next
For i = -12 To 12
Picture1.Line (0, i)-(0.15, i)
If i <> 0 And i Mod 2 = 0 Then Picture1.Print i
Next
End Sub
‘例子中可以显示坐标系,如不需要显示删除那一段代码即可
Private Sub Command1_Click()
'绘制f(x)=8*sin(x)正弦波
Picture1.DrawWidth = 2 '设置绘图线宽(点大小)
Dim y As Double
For x = -12 To 12 Step 0.01
y = 8 * Sin(x)
Picture1.PSet (x, y), vbRed '按点绘图,颜色为红色
Next
End Sub
Private Sub Form_Load()
Command1.Caption = "绘图"
Command1.Height = 380
Command1.ToolTipText = "绘制f(x)=8*sin(x)正弦波"
Picture1.AutoRedraw = True
End Sub
Private Sub Form_Resize()
'调整图片框位置与大小
On Error Resume Next
Picture1.DrawWidth = 1
Command1.Top = Me.ScaleHeight - Command1.Height - 100
Command1.Left = Me.ScaleWidth / 2 - Command1.Width / 2
Picture1.Cls
Picture1.Width = Me.ScaleWidth - 20
Picture1.Height = Me.ScaleHeight - 700
Picture1.Move 0, 100
'建立坐标系
Picture1.Scale (-12, 12)-(12, -12) '设置picture坐标从左上角的(X,Y)到右下角的(X,Y)的坐标
'显示坐标
Picture1.Line (-12, 0)-(12, 0)
Picture1.Line (0, 12)-(0, -12)
For i = -12 To 12
Picture1.Line (i, 0)-(i, -0.5)
Picture1.Print i
Next
For i = -12 To 12
Picture1.Line (0, i)-(0.15, i)
If i <> 0 And i Mod 2 = 0 Then Picture1.Print i
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询