-
Dec 24th, 2021, 09:20 AM
#1
Thread Starter
Lively Member
(VB6) - Zoom up image and reverse
Hello. With this code I make a kind of zoom out of an image.
It starts from the size of the image and reaches up
to 0 and here it starts again from the maximum.
Code:
Dim dblstep As Double
Timer1.Interval = 50
Me.ScaleMode = 3
dblstep = -2 '10 pixels
End Sub
Private Sub Timer1_Timer()
With Image1
.Move .Left, .Top, .Width + dblstep, .Height + dblstep
If .Width = 1 Then
'Timer1.Enabled = False
Image1.Width = 65
Image1.Height = 65
End If
End With
End Sub
And so far so good. I tried to make the way in reverse .
Then start the cycle from scratch to the maximum
of the image and start again.
I obviously tried changing.I removed the minus sign
Code:
Timer1.Interval = 50
Me.ScaleMode = 3
dblstep = 2 '10 pixels
End Sub
It seems to work but does not repeat the cycle
and does not start again. How to do it? Where to edit?
Thanks.
Giorgina
Last edited by Giorgina; Dec 24th, 2021 at 09:24 AM.
-
Dec 24th, 2021, 03:45 PM
#2
Re: (VB6) - Zoom up image and reverse
You're not showing all the code. You have an End Sub in the middle.
If you want it to cycle, then the code that checks for the end of a cycle (in the timer event code) needs to setup for the next cycle.
Code:
'pseudo code
Sub Timer1_Timer()
Adjust size
If Width = 1 Then
dblstep = 2
elseif Width = 65 Then
dblstep = -2
end if
You wouldn't set the size directly to 65, you let it work its way back to 65 by inverting the step value.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Dec 24th, 2021, 04:04 PM
#3
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
Yes,
I had not copied all the code. Sorry.
Missing just a line in the code that I had proposed
The complete code is: (with Form_load)
Code:
Dim dblstep As Double
Private Sub Form_Load()
Timer1.Interval = 10
Me.ScaleMode = 3
dblstep = -2 '10 pixels
End Sub
Private Sub Timer1_Timer()
With Image1
.Move .Left, .Top, .Width + dblstep, .Height + dblstep
If .Width = 1 Then
Image1.Width = 65
Image1.Height = 65
End If
End With
End Sub
I still tried to edit with your tip but it is not solved either.
Last edited by Giorgina; Dec 24th, 2021 at 04:09 PM.
-
Dec 24th, 2021, 05:56 PM
#4
Re: (VB6) - Zoom up image and reverse
What does your edit look like.
I posted pseudo code so it can't be used as is, you have to translate the pseudo code to real code.
I just copied your code into a project, and added the logic I wrote in pseudo code and the image shrinks to a point and then expands out to 65x65 and then shrinks to a point and then expands out to 65x65 continually.
I don't know if that is what you want, but it works the way I figured it should if the pseudo code was implemented correctly.
Also I changed dblstep to be an Integer. I didn't see any reason it needed to be a floating point number.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Dec 25th, 2021, 02:01 AM
#5
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
I have already explained what I want is:
that now my code correctly produces a zoom OUT,
and I would like to get a zoom IN of the image.
and more precisely:
now it goes from 65 up to 0. I want to get from 0 up to 65
-
Dec 25th, 2021, 04:54 AM
#6
Re: (VB6) - Zoom up image and reverse
If .Width = 1 Then
'Timer1.Enabled = False
Image1.Width = 65
Image1.Height = 65
you need to reverse this
Code:
If .Width = 65 Then ' when at max size
Image1.Width = 1 ' Change to point
Image1.Height = 1
End If
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 25th, 2021, 08:10 AM
#7
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
westconn1,
It's perfect !
That's what I wanted to have !!!
Now I just have to integrate the routine into my schedule.
the solution was simple but I had long tried and I don't know if I would get there.
Code:
Dim dblstep As Double
Private Sub Form_Load()
Timer1.Interval = 10
Me.ScaleMode = 3
dblstep = 2 '10 pixels
End Sub
Private Sub Timer1_Timer()
With Image1
.Move .Left, .Top, .Width + dblstep, .Height + dblstep
If .Width = 65 Then ' when at max size
Image1.Width = 1 ' Change to point
Image1.Height = 1
End If
End With
'Timer1.Enabled = True
End Sub
Thank you.
Solved !!!
-
Dec 26th, 2021, 03:00 AM
#8
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
It works but one thing is not clear to me:
I can increase the width 65,75,85,.... only.
And not with any value or
that does not contain the 5.
-
Dec 26th, 2021, 06:20 AM
#9
Re: (VB6) - Zoom up image and reverse
i tested you code from post #7 i do not see this problem
image width at each iteration
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
3
5
7
9
11
13
15
17
steps of 2 as expected
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 26th, 2021, 06:53 AM
#10
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
Ok, thanks
-
Dec 26th, 2021, 08:53 AM
#11
Hyperactive Member
Re: (VB6) - Zoom up image and reverse
Giorgina, With this method, the image gradually appears from around the corner in parts.
I made two Pictureboxes. The second is invisible. I scale the first one and copy the whole image from the second into it.
In this case, the entire drawing is scaled, not part of it.
Code:
Option Explicit
Dim dblstep As Integer
Private Sub Form_Load()
Timer1.Interval = 40
Me.ScaleMode = 3
Picture1.ScaleMode = 3
Picture1.AutoSize = True
Picture1.BorderStyle = 0
Picture2.ScaleMode = 3
Picture2.AutoSize = True
'Loading the image 160X176 piexels
Picture2.Picture = LoadPicture(App.Path & "\1.jpg")
Picture2.Visible = False
' Aligning the pictureboxes
Picture1.Width = Picture2.Width
Picture1.Height = Picture2.Height
dblstep = 2
End Sub
Private Sub Timer1_Timer()
Timer1.Interval = 40
With Picture1
If .Width = 1 Or .Height = 1 Then
dblstep = 2
Timer1.Interval = 1500
ElseIf .Width >= Picture2.Width Or .Height >= Picture2.Height Then
dblstep = -2
Timer1.Interval = 1500
End If
.Width = .Width + dblstep
.Height = .Height + dblstep
'Place Picture1 in the center of the form
.Move Form1.ScaleWidth / 2 - (.Width) / 2, Form1.ScaleHeight / 2 _
- (.Height) / 2, .Width + dblstep, .Height + dblstep
'Clear Picture1 and copy the whole image from Picture2 into it.
Picture1.Cls
.PaintPicture Picture2, 0, 0, Picture1.Width, Picture1.Height _
+ dblstep, 0, 0, Picture2.Width, Picture2.Height, vbSrcAnd
End With
End Sub
Unfortunately, there is a slight flicker in the image.
-
Dec 26th, 2021, 09:31 AM
#12
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
Very interesting alternative, Argus19. Definitely to be expanded.
For example, to make the cycle repeat itself endlessly, after
the image has made the reverse path.
The flashing I think is inevitable (with the timer)
-
Dec 26th, 2021, 11:44 AM
#13
Hyperactive Member
Re: (VB6) - Zoom up image and reverse
There is an endless loop with stops when the maximum and minimum image size is reached.
-
Dec 26th, 2021, 12:00 PM
#14
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
Yes, I understand. but for now your code does not do it yet .
by me at least not. When it reaches the minimum image size is reached.
of the image now stops and says:
Code:
invalid procedure call or argument.
That is why I said that we needed to improve
and maybe the cycle or lus.
-
Dec 26th, 2021, 12:17 PM
#15
Hyperactive Member
Re: (VB6) - Zoom up image and reverse
Perhaps I did not take into account something. Take a look:
https://disk.yandex.ru/d/F9gbsSVP4QMgLg
-
Dec 26th, 2021, 12:29 PM
#16
Thread Starter
Lively Member
Re: (VB6) - Zoom up image and reverse
Yess. I downloaded and this version is fine.
The problem before was with the image .
Now it looks and works perfectly.
I now study and will serve as a valid alternative.
Thank you
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
|