|
-
Jun 17th, 2016, 02:51 AM
#1
Thread Starter
Member
Expand image with animation
The code below animates the resizing effect properly but from the left corner of the image. How can it be done from the center expanding in all directions?
Code:
Private Sub Timer1_Timer()
If Image1.Width >= 2916 Then
Image1.Width = 2916
Timer1.Enabled = False
Exit Sub
End If
Image1.Width = Image1.Width + 50
Image1.Height = Image1.Height + 50
End Sub
Thanks
-
Jun 17th, 2016, 08:02 AM
#2
Re: Expand image with animation
Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB6 and earlier' forum
-
Jun 17th, 2016, 08:59 AM
#3
Re: Expand image with animation
Code:
Private Sub Timer1_Timer()
If Image1.Width >= 2916 Then
Image1.Width = 2916
Timer1.Enabled = False
Exit Sub
End If
Image1.Top = Image1.Top - 25
Image1.Left = Image1.Left - 25
Image1.Width = Image1.Width + 50
Image1.Height = Image1.Height + 50
End Sub
-
Jun 17th, 2016, 09:18 AM
#4
Thread Starter
Member
Re: Expand image with animation
It has to expand in ALL directions from the CENTER of the Picture box
-
Jun 17th, 2016, 09:51 AM
#5
Re: Expand image with animation
It does expand in all directions... you just need to set the start position (presumably top and left of 2916/2) and size (0).
-
Jun 17th, 2016, 10:31 AM
#6
Re: Expand image with animation
In other words, if Image1 is inside a picturbox, you have to center Image1 in the picturebox at the start.
Then, as the Image1 is expanded, it is also moved (top, left) to keep the center of Image1 at the same location it started, which will be the center of the picturebox, if you had it centered in the picturebox to start with.
-
Jun 17th, 2016, 01:03 PM
#7
Re: Expand image with animation
This example preserves the aspect ratio of the specified image as it is enlarged:
Code:
Option Explicit 'Copy & paste in a blank Form
Private Const HALF As Single = 0.5!
Private m_AspectRatio As Single
Private Image1 As VB.Image
Private Picture1 As VB.PictureBox
Private WithEvents Timer1 As VB.Timer
Private Sub Form_Activate()
Const PROMPT = "No picture data or picture filename found in the Clipboard!" & vbCrLf & vbCrLf & "Try again?"
Const STYLES = vbCritical Or vbRetryCancel Or vbDefaultButton1
WindowState = vbMaximized
Set Picture1 = Controls.Add("VB.PictureBox", "Picture1")
Set Image1 = Controls.Add("VB.Image", "Image1", Picture1)
Do: Select Case True
Case Clipboard.GetFormat(vbCFText): On Error Resume Next
Image1 = LoadPicture(Replace(Clipboard.GetText, """", vbNullString))
On Error GoTo 0
Case Clipboard.GetFormat(vbCFBitmap): Image1 = Clipboard.GetData
End Select
If Image1.Picture.Handle Then Exit Do
If MsgBox(PROMPT, STYLES) = vbCancel Then Unload Me: Exit Sub
Loop
Picture1.Move ScaleLeft, ScaleTop, ScaleWidth, ScaleHeight
Picture1.ScaleMode = vbPixels
Picture1.Visible = True
Image1.Move Picture1.ScaleWidth * HALF, Picture1.ScaleHeight * HALF, 0!, 0!
Image1.Stretch = True
Image1.Visible = True
m_AspectRatio = Image1.Picture.Width / Image1.Picture.Height
Set Timer1 = Controls.Add("VB.Timer", "Timer1")
Timer1.Interval = 1&
End Sub
Private Sub Timer1_Timer()
Dim NewWidth As Single, NewHeight As Single
With Image1
If .Width < Picture1.ScaleWidth And .Height < Picture1.ScaleHeight Then
NewWidth = .Width + 2! 'Pixels
NewHeight = NewWidth / m_AspectRatio
.Move .Left - 1!, .Top - (NewHeight - .Height) * HALF, NewWidth, NewHeight
Else
Timer1 = False
End If
End With
End Sub
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Jun 17th, 2016, 02:56 PM
#8
Re: Expand image with animation
-
Jun 18th, 2016, 04:47 AM
#9
Thread Starter
Member
Re: Expand image with animation
Seems to do what I need! Many thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|