| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 522 人关注过本帖
标题:帮忙添加一部分可以实现缩放
取消只看楼主 加入收藏
xmmx210
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-6-14
结帖率:0
收藏
 问题点数:0 回复次数:0 
帮忙添加一部分可以实现缩放
麻烦大家在程序里加以部分,可以实在图片一边运动一边缩放的效果 谢谢!

Option Explicit
   Private Declare Function BitBlt Lib "GDI32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
    Private Declare Function StretchBlt Lib "GDI32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
     Const SRCCOPY = &HCC0020
     Const SRCAND = &H8800C6
     Const SRCPAINT = &HEE0086
     Const CelWidth = 60           '动画的宽度
     Const CelHeight = 100          '动画的高度
     Const CelCount = 3            '动画帧的个数


     Dim CelNum As Long                'CelNum 为当前的动画帧


     Dim Forward As Long               '蝴蝶从左向右飞/从右向左飞的标志
     Dim Down As Long                  '蝴蝶从上向下飞/从下向上飞的标志
     Dim CurrentLeft As Long           ' 动画帧的X坐标
     Dim CurrentTop As Long            ' 动画帧的Y坐标
     Dim OldLeft As Long               ' 上一次动画帧的X坐标
     Dim OldTop As Long                    ' 上一次动画帧的Y坐标
 

     Function MaxSingle(A As Single, B As Single) As Single    '求单精度变量A、B的最大值
         If A > B Then
            MaxSingle = A
           Else
            MaxSingle = B
           End If
     End Function
     
  
      Function MinSingle(A As Single, B As Single) As Single    '求单精度变量A、B的最小值
         If A < B Then
            MinSingle = A
           Else
            MinSingle = B
           End If
     End Function


     Private Sub form1_Paint()
           Dim temp As Long
           Dim SrcWidth As Long
           Dim CurrentX As Long

           If Forward Then     '当蝴蝶从左向右飞时
                SrcWidth = CelWidth
                CurrentX = CurrentLeft
             Else                 '当蝴蝶从右向左飞时,SrcWidth应设置成负值,蝴蝶将掉头
                SrcWidth = -CelWidth
                CurrentX = CurrentLeft + CelWidth - 1
           End If


           temp = BitBlt(Form1.hDC, OldLeft, OldTop, CelWidth, CelHeight, BufferPicture.hDC, 0, 0, SRCCOPY)
           temp = BitBlt(BufferPicture.hDC, 0, 0, CelWidth, CelHeight, Form1.hDC, CurrentLeft, CurrentTop, SRCCOPY)
           temp = StretchBlt(Form1.hDC, CurrentX, CurrentTop, SrcWidth, CelHeight, SpritePic.hDC, CelNum * CelWidth, CelHeight + 5, CelWidth, CelHeight, SRCAND)
           temp = StretchBlt(Form1.hDC, CurrentX, CurrentTop, SrcWidth, CelHeight, SpritePic.hDC, CelNum * CelWidth, 0, CelWidth, CelHeight, SRCPAINT)
           OldLeft = CurrentLeft
           OldTop = CurrentTop
0
           CelNum = CelNum + 1    '动画帧计数
           If CelNum > CelCount - 1 Then CelNum = 0 '动画显示到最后一帧时,将CelNum置为0
           BufferPicture.Refresh  '本条语句使我们能看到BitBlt()的处理过程,它是可选的
       End Sub


       Private Sub Form_Activate()
            Dim temp As Long
            CelNum = 0
            Form1.Picture = LoadPicture(App.Path & "\5.jpg")
            SpritePic.Picture = LoadPicture(App.Path & "\6.jpg")
            Form1.Refresh        '本条语句很重要,它将窗体的背景图像刷新
            temp = BitBlt(BufferPicture.hDC, 0, 0, CelWidth, CelHeight, Form1.hDC, CurrentLeft, CurrentTop, SRCCOPY)
            End Sub

       Private Sub Form_Load()
            Forward = True
            Down = True
            CurrentLeft = 0
            CurrentTop = 0
       End Sub


       Private Sub Timer1_Timer()
           Dim border As Single     '窗口边界
           '蝴蝶遇到窗口边界时颠倒运动方向
           If (((CurrentLeft + CelWidth) >= Form1.ScaleWidth - 9 * CelWidth) And Forward) Then
               Forward = False
           ElseIf ((CurrentLeft <= 0) And Not Forward) Then
               Forward = True
           End If
              '计算蝴蝶的X坐标
           If Forward Then
                border = Form1.ScaleWidth - CelWidth
                CurrentLeft = MinSingle(CurrentLeft + 15, border)
           Else
                 border = CelWidth
                 CurrentLeft = MaxSingle(CurrentLeft - 15, 0)
           End If
            '判断蝴蝶是否超出窗口的上下坐标
           If (((CurrentTop + CelHeight) >= Form1.ScaleHeight - 22 * CelHeight) And Down) Or ((CurrentTop <= 0) And Not Down) Then
                 Down = Not Down
           End If
           '计算蝴蝶的Y坐标
           If Down Then
                  border = Form1.ScaleHeight - CelHeight
                  CurrentTop = MinSingle(CurrentTop + 6, border)
           Else
                CurrentTop = MaxSingle(CurrentTop - 6, 0)
           End If
           form1_Paint     '调用Paint事件更新动画的显示
      End Sub
搜索更多相关主题的帖子: 图片 运动 
2012-06-18 21:46
快速回复:帮忙添加一部分可以实现缩放
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021071 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved