资源描述
第11章图形图像处理,贺向前,主要内容,计算机坐标系统 常用作图方法 作图相关属性 作图的相关函数,计算机坐标系统,显示器坐标系统,计算机坐标系统,窗口等容器的坐标系统,计算机坐标系统,坐标系统的度量单位 object.ScaleMode = value,计算机坐标系统,自定义度量单位 Object.ScaleWidth=w 把对象的宽度定义为有w个刻度单位 Object.ScaleHight=h 把对象的高度定义为有h个刻度单位 Object.ScaleLeft=X 当X0,对象的坐标系统的横坐标向左平移X个度量单位 当X0,对象的坐标系统的纵坐标向上平移Y个度量单位 当Y0,对象的坐标系统的纵坐标向下平移Y个度量单位,计算机坐标系统,自定义度量单位 Object.Scale(x1,y1)-(x2,y2) (x1,y1):新坐标系下对象左上角的坐标 (x2,y2):新坐标系下对象右下角的坐标,计算机坐标系统,例 把窗体的坐标系统的长宽分别定义为100个单位,坐标原点移动到窗体的中央,Private Sub Form_Load() Me.AutoRedraw = True Me.ScaleWidth = 100 Me.ScaleHeight = 100 Me.ScaleLeft = -50 Me.ScaleTop = -50 Me.Line (-50, 0)-(50, 0) Me.Line (0, -50)-(0, 50) End Sub,计算机坐标系统,把窗体的坐标系统的长宽分别定义为100个单位,坐标原点移动到窗体的中央,Private Sub Form_Load() Me.AutoRedraw = True Me.Scale(-50,-50)-(50,50) Me.Line (-50, 0)-(50, 0) Me.Line (0, -50)-(0, 50) End Sub,计算机坐标系统,如何把上例中的纵坐标的方向设置为向上?并标出如图所示的原点和X、Y,常用作图方法,画线Line方法 Object.Line(x1,y1)-(x2,y2),Color 画矩形Line方法 Object.Line(x1,y1)-(x2,y2),Color,BF 如果没有使用参数F,则填充模式和填充颜色分别由Object的FillStyle和FillColor决定,否则画一个实心的矩形,边框线颜色和填充颜色均由Color决定;,例 画出5条长度相同平行的线段,Option Explicit Private Sub Form_Click() Dim i% For i = 1 To 5 Line (500, 500 * i + 100)-(2500, 500 * i + 100) Next i End Sub,例 画出5个同心矩形,Option Explicit Private Sub Form_Click() Dim i%, x1%, y1%, x2%, y2% Me.Scale (-50, 50)-(50, -50) Me.Line (-50, 0)-(50, 0) Me.Line (0, 50)-(0, -50) For i = 1 To 5 x1 = -50 + 5 * i y1 = 50 - 5 * i x2 = 50 - 5 * i y2 = -50 + 5 * i Me.Line (x1, y1)-(x2, y2), , B Next i End Sub,例:画出如图所示图形,Private Sub Form_Click() Dim i%, j%, t#, N%, r#, xi#, yi#, xj#, yj# Const pi# = 3.14159265358979 N = 15: r = 3 t = 2 * pi / N For i = 1 To N For j = 1 To N If i j Then xi = r * Cos(i * t) + 0 yi = r * Sin(i * t) + 0 xj = r * Cos(j * t) + 0 yj = r * Sin(j * t) + 0 Line (xi, yi)-(xj, yj) End If Next j Next i End Sub,Private Sub Form_Load() Me.Width = Me.Height Me.Scale (-4, 4)-(4, -4) End Sub,Line方法中的Step关键字,Private Sub Form_Load() Me.AutoRedraw = True Me.Scale (-200, 200)-(200, -200) Dim i% Me.CurrentX = -180 Me.CurrentY = 150 For i = 1 To 9 Me.Line -Step(20, 0) Me.Line -Step(0, -200) Me.Line -Step(20, 0) Me.Line -Step(0, 200) Next i End Sub,常用作图方法,画圆Circle方法 Object.Circle(x,y),R,Color,Start,End,Aspect 按逆时针方向画圆 Start,End为画圆弧起始和结束的弧度。如果为负数,则先要画一条半径,然后把Start,End处理成正数; Aspect决定画一个椭圆的纵横坐标比(为1画圆),例 画出5个同心圆,Option Explicit Private Sub Form_Click() Dim i%, x%, y% x = Me.ScaleWidth / 2 y = Me.ScaleHeight / 2 Me.ScaleLeft = -x Me.ScaleTop = -y Me.Line (-x, 0)-(x, 0) Me.Line (0, y)-(0, -y) For i = 1 To 5 Me.Circle (0, 0), 200 + 200 * i Next i End Sub,例:行星绕太阳转,Const PI# = 3.14159265358979 Private Sub Form_Click() Me.Scale (-4000, 2000)-(4000, -2000) Me.FillStyle = 0 Me.FillColor = RGB(255, 255, 0) Me.Circle (0, 0), 400, vbRed Me.FillStyle = 1 Me.Circle (0, 0), 3200, vbBlue, , , 0.5 Me.DrawMode = 7 Timer1.Enabled = True Me.FillStyle = 0 End Sub Private Sub Form_Load() Me.Height = 2700 Me.Width = 4800 Timer1.Interval = 10 Timer1.Enabled = False End Sub,Private Sub Timer1_Timer() Static alfa#, flag, x#, y# flag = Not flag If flag Then alfa = alfa + PI / 10 If alfa 2 * PI Then alfa = 0 x = 3200 * Cos(alfa) y = 1600 * Sin(alfa) Me.Circle (x, y), 300 End Sub,常用作图方法,画点PSet方法 Object.PSet (X,Y),Col Cls方法 Move方法,例9.5 画出2个周期的正弦波形,Option Explicit Private Sub Form_Click() Dim i%, x#, y# Const pi# = 3.14159265358979 Me.Scale (-2 * pi, 1.2)-(2 * pi, -1.2) Me.Line (-2 * pi, 0)-(2 * pi, 0) Me.Line (0, 1.2)-(0, -1.2) For x = -2 * pi To 2 * pi Step 0.01 y = Sin(x) Me.PSet (x, y) Next x End Sub,例:画出如图所示的图形,Private Sub Form_Click() Dim a#, r#, x#, y# Const pi# = 3.14159265358979 r = 4 For a = 0 To 2 * pi Step 0.001 x = r * Cos(4 * a) * Cos(a) y = r * Cos(4 * a) * Sin(a) Me.PSet (x, y) Next a End Sub Private Sub Form_Load() Me.Width = Me.Height Me.Scale (-4, 4)-(4, -4) End Sub,常用作图方法,PaintPicture方法 picDes.PaintPicture picSrc.Picture, _ picDes.Left, picDes.Top, _ picDes.Width, picDes.Height, _ picSrc.Left, picSrc.Top, _ picSrc.Width, picSrc.Height, vbSrcCopy,作图相关属性,CurrentX, CurrentY属性 设置光标的坐标位置 object. CurrentX = number object. CurrentY = number,作图相关属性,DrawStyle 决定图形方法输出的线型的样式 object.DrawStyle = number number 的设置值为:,例 画出7条长度相同平行的线段,Option Explicit Private Sub Form_Click() Dim i% Me.Scale (-50, -50)-(50, 50) For i = 0 To 6 Me.DrawStyle = i Me.Line (-40, -40 + 5 * i)-(40, -40 + 5 * i) Next i End Sub,作图相关属性,DrawWidth 设置图形方法输出的线宽 object.DrawWidth = size,Option Explicit Private Sub Form_Click() Dim i% Me.Scale (-50, -50)-(50, 50) For i = 1 To 12 Me.DrawWidth = i Me.Line (-40, -40 + 6 * i)-(40, -40 + 6 * i) Next i End Sub,作图相关属性,FillStyle 设置填充模式 object.FillStyle = number,例画出8个并排的圆,Option Explicit Private Sub Form_Click() Dim i% For i = 0 To 7 Me.FillStyle = i Me.Circle (500 + 800 * i, 800), 400 Next i End Sub,作图相关函数,LoadPicture(“FileName”) SavePicture picture, “FileName” RGB(0-255,0-255,0-255) QBColor(0-15),Thanks for your attendance,
展开阅读全文