在VB6中实现图像的变换

王朝厨房·作者佚名  2007-01-04
宽屏版  字体: |||超大  

文/黄艳秋

Visual Basic 6.0(简称VB6)是微软公司推出的当前世界上最流行的可视化编程工具,特别在数据库及多媒体开发方面的强大支持与改进,使我们能轻松地开发出各种功能极强的数据库及多媒体应用程序。下面介绍的是在多媒体应用中图像变换技术的“马赛克”效果实例。

实现过程及效果

“马赛克”效果主要是用方块填充某一图像框,从而得到“马赛克”效果。先在窗体中绘制两个图像框,将图像载入一图像框中,同时将另一个图像框设为空白,然后调用API函数BitBlt将左框中的图像按照一定的顺序以方块为单位复制到右框中,就可以实现“马赛克”的动态图像效果。

实现步骤

1、窗体中加入两个图像框Picture1和Picture2,两个命令按钮Command1和Command2;

2、载入窗体同时,在Picture1中载入图片;

3、在Command1_Click事件中调用BitBlt函数和Sleep函数。

程序代码及注释

Private Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)

然后,就对API函数‘BitBlt进行声明。

Const copy_put = &&HCC0020

Sub Form_Load()

Picture1.Picture = LoadPicture("c:My Documentsm7.bmp")‘载入图像

Picture1.ScaleMode = 3‘像素单位

End Sub

Private Sub Command1_Click()

Picture2.Cls‘设为空白

h% = Picture1.ScaleHeight‘图像高度

w% = Picture1.ScaleWidth‘图像宽度

changwidth = 15‘方块的宽度

changheight = 15‘方块高度

For i = 0 To w% Step changwidth * 2‘水平轴错开表示图像

For j = 0 To h% Step changheight * 2

x = DoEvents()

s% = BitBlt(Picture2.hDC, i, j, changwidth, changheight, Picture1.hDC, i, j, copy_put)‘调用BitBlt

Sleep (100)‘延时

Next j

Next i

For i = changwidth To w% Step changwidth * 2

For j = chang-

height To h% Step changheight * 2

x = DoEvents()

s% = BitBlt(Picture2.hDC, i, j, changwidth, changheight, Picture1.hDC, i, j, copy_put)

Sleep (100)

Next j

Next i

For i = 0 To w% Step changwidth * 2

For j = changheight To h% Step changheight * 2

x = DoEvents()

s% = BitBlt(Picture2.hDC, i, j, changwidth, changheight, Picture1.hDC, i, j, copy_put)

Sleep (100)

Next j

Next I

For i = changwidth To w% Step changwidth * 2

For j = 0 To h% Step changheight * 2

x = DoEvents()

s% = BitBlt(Picture2.hDC, i, j, changwidth, changheight, Picture1.hDC, i, j, copy_put)

Sleep (100)

Next j

Next I

End Sub

Private Sub Command2_Click()

End

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有