Animation




Dim NumFrame As Integer, Frame As Integer
Dim XCount As Integer, YCount As Integer
Dim FrameWidth As Long, FrameHeight As Long
Dim FrameScreenX As Long, FrameScreenY As Long
Private Sub Form_Load()
'Starting frame

Frame = 1

'Numero totale dei frames..

NumFrame = 18
'Numero frames orizontali(Grid X)

XCount = 6
'Numero frames verticali(Grid Y)

YCount = 3
'Calcola la dimensione della picture nella

FrameWidth = (Picture1.Width / XCount) / Screen.TwipsPerPixelX
FrameHeight = (Picture1.Height / YCount) / Screen.TwipsPerPixelY
'Calcola il centro del form / object per visualizzare

'l'animazione

FrameScreenX = ((Me.Width / Screen.TwipsPerPixelY) / 2) - (FrameWidth / 2)
FrameScreenY = ((Me.Height / Screen.TwipsPerPixelY) / 2) - (FrameHeight / 2)
End Sub

'Codice del Timer

Private Sub Timer1_Timer()
'Incolla con BitBlt

Call CopyFrame(Picture1, Me.hdc, Frame)
Frame = Frame + 1
If Frame > NumFrame Then Frame = 1
End Sub

Private Sub CopyFrame(SrcControl As Control, DestHDC As Long, FrameNum As Integer)
Dim CompDC As Long, hBmp As Long
Dim SourceHDC As Long, SourceBMP As Long
Dim xpos As Long, ypos As Long, rtn As Long
'handle del controllo vpicture

SourceHDC = SrcControl.hdc

'carica la picture

SourceBMP = SrcControl.Picture

'Crea un Device context compatibile in memoria

CompDC = CreateCompatibleDC(SourceHDC)

'Seleziona la picture sul device context compatibile

hBmp = SelectObject(CompDC, SourceBMP)
'Calcola le x-cor dai frames

xpos = (IIf((FrameNum Mod XCount) = 0, XCount, FrameNum Mod XCount)) - 1
'Calcola le y-cor dai frames

ypos = (FrameNum - 1) \ XCount
'Copia le x-cor;y-cor sul device context.(appare il frame)

rtn = BitBlt(DestHDC, FrameScreenX, FrameScreenY, FrameWidth, _
FrameHeight, CompDC, xpos * FrameWidth, ypos * FrameHeight, SRCCOPY)
'Cancella il device context e libera la memoria

rtn = DeleteDC(CompDC)
End Sub

Inserire un Timer nel progetto ed un controllo picture
Assegnare al Timer un Intervallo 10ms ed abilitarlo.
Caricare l'immagine animata nella Picture










( animation.html )- by Paolo Puglisi - Modifica del 17/12/2023