1,000,000 $ question...answer and win!! :)

europe

Member
hello and welcome to my 1,000,000 $ question....be the first to answer and win 1,000,000 $ (virtually of course :sign0147:)

that's the issue:

I have a form, with an image 1500x500 streched. I'm using ImageScroller from Byak@ and i wrote an easy function to zoom in/out the image (basically add more pixel to the streched image).

Well, I'd like to make the zoom scrolling the image to the same point at the centre of the screen, so the new zoomed image has the same view centered as the 1:1 image.

here is the code for explain better; under the code i've linked a pic to show better what i need.

B4X:
Sub dzem_MagicEvent ' -----> Byak@ SCROLL IMAGE
If down=1  Then
Dim LowWord, HighWord, X, Y
LowWord = bit.OR2(dzem.lParam, 4294901760)
X = bit.XOR2(LowWord, 4294901760)
HighWord = bit.OR2(dzem.lParam, 65535)
Y = bit.XOR2(HighWord, 65535)/2^16
Img.Left = Img.Left - (DownX - X)
Img.Top = Img.Top - (DownY - Y)
End If
End Sub

Sub zoominbtn_Click ' ------> ZOOM IN FUNCTION
If zoom < 3 AND zoom >= -3 Then
  Img.Width = Img.Width + 200
  Img.Height = Img.Height +  100
    Img.Left = Img.Left - ' WHICH VALUE!?!?
    Img.Top = Img.Top - ' WHICH VALUE!?!?
  zoom=zoom+1
End If
End Sub

Sub zoomoutbtn_Click      ' ------> ZOOM IN FUNCTION
  If zoom <= 3 AND zoom > -3 Then
  Img.Width = Img.Width - 200
  Img.Height = Img.Height - 100
    Img.Left = Img.Left + ' WHICH VALUE!?!?
    Img.Top = Img.Top + ' WHICH VALUE!?!?
  zoom=zoom-1
  End If
End Sub

wfJf.jpg


The grey part is the one i get right now, but i want to get the centered part (what a wonderful nose, uh? :p).

Any help will be muuuuuch appreciated thanks as always in advance! :sign0060:

-Europe
 
Last edited:

klaus

Expert
Licensed User
Longtime User
For me the .Left and .Top values should be changed by the half of the values you add or subtract from the width or the height.

In your case
Img.Left = Img.Left + 100
Img.Top = Img.Top + 50

or
Img.Left = Img.Left - 100
Img.Top = Img.Top - 50

I don't know what to do with 1,000,000 $

Best regards.
 

europe

Member
already tried but when you're at the edge of the img, the zoom will bring you progressivly to the centre of the img; so it's working right only near the centre of the image.....i think I should use some math functions...but which one :confused:
 

klaus

Expert
Licensed User
Longtime User
You are right, I didn't look at depp enough.

You should use following formulas.

Old coordinates of screen midle
x = Img.Left + HalfScreenWidth
y = Img.Top + HalfScreenheight

New coordinates of screen middle
x = x * Img.WidthNew/Img.WidthOld
y = y * Img.HeightNew / Img.HeightOld

Img.Left = x - HalfSrceenWidth
Img.Top = y - HalfScreenHeight

The principle doesn't work when unzooming and the screen is neer the left and or the top.

Best regards.
 
Top