VB中实现图像特技(2)
2006-02-27 11:52:53 来源:WEB开发网
核心提示:->设置各控件的属性如下:Form1:AutoRedraw:TrueScaleMode:3Picture1:AutoRedraw:TrueScaleMode:3Visible:False2代码编写Modull.bas中的内容(声明BitBlt函数):PublicConstSRCCOPY=&HCC0020'(DW
->设置各控件的属性如下:
Form1:AutoRedraw:True
ScaleMode:3
Picture1:AutoRedraw:True
ScaleMode:3
Visible:False
2代码编写
Modull.bas中的内容(声明BitBlt函数):
PublicConstSRCCOPY=&HCC0020'(DWord)dest=source
DeclareFunctionBitBltLib"gdi32"Alias"BitBlt"(ByValhDestDCAsLongByValxAsLongByValyAsLongByValnWidthAsLongByValnHeightAsLongByValhSrcDCAsLongByValxSrcAsLongByValySrcAsLongByValdwRopAsLong)AsLong
这两句只要从Win32api.txt文件中粘贴即可。
Form1中的代码:
在Declare中定义全局变量:
Constbmpfilemax=5&总共5个bmp文件
Dimbmpfile(bmpfilemax)AsString&bmp文件的文件名数组
Dimdrawbmpmode(bmpfilemax)AsInteger&各画显示时的切换方式
Dimbmpnum,movestep,xmax,ymaxAsInteger
DimkxyAsSingle&x,y二个方向的比例
程序运行时先作初始化工作:
PRivateSubForm-Load()
bmpnum=0&当前文件号=0,第一个文件
bmpfile(0)=App.Path ''\bmp1.bmp''bmpfile(1)=App.Path ''\bmp2.bmp''
bmpfile(2)=App.Path ''\bmp3.bmp''
bmpfile(3)=App.Path ''\bmp4.bmp''
bmpfile(4)=App.Path ''\bmp5.bmp''
drawbmpmode(0)=1
drawbmpmode(1)=5
drawbmpmode(2)=3
drawbmpmode(3)=4
drawbmpmode(4)=2
movestep=0&步进参数
xmax=Form.ScaleWidth/2
ymax=Form.ScaleHeight/2
kxy=ymax/xmax
Picture1.Picture=LoadPicture(bmpfile(bmpnum))
Timer1.Interval=30&定时器起动
EndSub
响应鼠标:
PrivateSubForm-Click()
End&当有击鼠标动作时程序结束
EndSub
切换演示工作主要在定时器中完成:
PrivateSubTimer1-Timer()
hDestDC=Form1.HDC&目标DC
hSrcDC=Picture1.hDC&源DC,画是从不可见的Picture1中拷贝到窗体
drawflag=drawbmpmode(bmpnum)&当前画出现的方式
SelectCasedrawflag
Case1&从中间逐步放大
endmax=xmax&用于结束判断
X1=xmax-movestep
w=movestep*2
Y1=Cint(ymax-movestep*kxy)
h=Cint(2*movestep*kxy)
i=BitBlt(hDestDC,X1,Y1,w,h,hSrcDC,X1,Y1,SRCCOPY)
Case2&从左到右
endmax=xmax
w=movestep*2
h=Form1.ScaleHeight
i=BitBlt(hDestDC,0,0,w,h,hSrcDC,X1,Y1,SRCCOPY)
Case3'左右向中间
endmax=xmax
w=movestep
h=Form1.ScaleHeight
i=BitBlt(hDestDC,0,0,w,h,hSrcDC,0,0,SRCCOPY)&左面部分
X1=Form1.ScaleWidth-movestep
i=BitBlt(hDestDC,X1,0,w,h,hSrcDC,X1,0,SRCCOPY)&左面部分
Case4'栅条状
endmax=CInt(2*xmax/10)&共分阶10条
tempi=CInt(2*xmax/10)
w=movestep
h=Form1.ScaleHeight
Forij=0To9
i=BitBlt(hDestDC,tempi*ij,0,w,h,hSrcDC,tempi*ij,0,SRCCOPY)
Nextij
Case5'棱形状
endmax=CInt(2*xmax/10)
tempi=CInt(2*xmax/10)
w=movestep
Forih=0Tow-1
Forik=0To9
Forij=0To9
l=tempi*ik tempi/2
t=tempi*ij tempi/2
i=BitBlt(hDestDC,1-(w-ih),t-ih,(w-ih)*2,1,hSrcDC,1-(w-ih),t-ih,SRCCOPY)
i=BitBlt(hDestDC,1-(w-ih),t ih,(w-ih)*2,1,hSrcDC,1-(w-ih),t ih,SRCCOPY)
Nextij
Nextik
Nextih
EndSelect
Form1.Refresh
movestep=movestep 2&步进增加
Ifmovestep>endmaxThen&若步进够大,画面都已显示,本张画结束切换
bmpnum=bmpnum 1&进到下一张画
Ifbmpnum>=bmpfilemaxThen&若5张画已显示完则再从第一张开始
bmpnum=0
EndIf
movestep=0
Picture1.Picture=LoadPicture(bmpfile(bmpnum))
EndIf
EndSub->
->
赞助商链接