VB中图像显示特效五例 云飞 2001年 32期 我们在一些演示程序中经常看到图像以马赛克、水平百叶窗、从左到右等形式出现,这些特殊的图像显示增加了动感,增强了演示效果。那么,在VB中如何实现这些显示特效呢?   #1一、编程原理   要使图像一部分一部分地显示出来,就需要先把图像分割成若干块,然后按设计的方式依次显示出来。在VB中有Pictureclip控件,利用它可以将图像分割成若干行和列,然后使用PaintPicture方法显示到Picture控件上。   #1二、程序代码   首先准备一张图片,要求其长和宽均是100的倍数,以方便我们分割。然后在窗体上放置一个Picture控件(Visible=False)、一个Pictureclip控件和一个Image控件。   Option Explicit   Dim i As Integer   Private Sub Form_Load()'主程序   Randomize   Picture1.Height = Image1.Height   Picture1.Width = Image1.Width   PictureClip1.Picture = Image1.Picture   End Sub   Sub ys()'延时子程序   Dim k As Integer   For k = 0 To 30000   Next   End Sub   1.从左到右显示   Private Sub Command1_Click()   Picture1.Cls '清除Picture1中的图像   PictureClip1.Cols = 100 '分割列数   PictureClip1.Rows = 1 '分割行数   For i = 0 To 99   ys '延时   Picture1.PaintPicture PictureClip1.GraphicCell(i), Picture1.Width / 100*(i),0   Next   End Sub   2.从上到下显示   Private Sub Command2_Click()   Picture1.Cls   PictureClip1.Cols = 1   PictureClip1.Rows = 100   For i = 0 To 99   ys   Picture1.PaintPicture PictureClip1.GraphicCell(i),0,Picture1.Height/100*(i)   Next   End Sub   3.从中间向两边伸展显示   Private Sub Command3_Click()   Picture1.Cls   PictureClip1.Cols = 100   PictureClip1.Rows = 1   For i = 0 To 49   ys   Picture1.PaintPicture PictureClip1.GraphicCell(i+50),Picture1.Width/100*(i + 50),0   Picture1.PaintPicture PictureClip1.GraphicCell(49-i),Picture1.Width/100*(49-i),0   Next   End Sub   4.水平百叶窗方式显示   Private Sub Command4_Click()   Picture1.Cls   PictureClip1.Cols = 1   PictureClip1.Rows = 100   Dim j As Integer   For i = 1 To 10   For j = 1 To 10   ys   Picture1.PaintPicture PictureClip1.GraphicCell((j - 1)) * 10 + i - 1), 0, Image1.Height / 100*((j - 1)* 10 + i - 1)   Next   Next   End Sub   5.以马赛克方式显示   Private Sub Command5_Click   Picture1.Cls   PictureClip1.Cols=10   PictureClip1.Rows=10   Dim temp(99) As Integer '定义数组   Dim j As Integer   temp(0) = Int(Rnd*100)'随机产生100个0到99之间不重复的数   For i = 1 To 99   a0:temp(i) = Int(Rnd*100)   For j = 0 To i - 1   If temp(i) = temp(j) Then GoTo a0   Next   Next   For i = 0 To 99 '根据随机数显示   ys   Picture1.PaintPicture PictureClip1.GraphicCell(temp(i)), Picture1.Width / 10*(temp(i) Mod 10),Image1.Height/10*(temp(i)\10)   Next   End Sub   怎么样?很爽吧!利用这个原理,还可以实现“从右到左”、“从下到上”、“从两边向中间闭合”、“垂直百叶窗”、“涡旋方式”等显示方式。开动你的脑筋,实现更多美妙的显示方式吧!