C
C#2w ago
Hermes

Implement Zooming in Drawing application

Trying to implement zooming on a canvas in such a way a that the point where the mouse is pointing at pre-zoom and post-zoom stays the same. Can't figure out why the offset isn't being calculated properly. I'm trying to adapt the logic gotten from here: https://youtu.be/ZQ8qtAizis4?si=zLbqZok2fDN5aNe-&t=874 I also found this: https://stackoverflow.com/questions/2916081/zoom-in-on-a-point-using-scale-and-translate The canvas is a Border control which holds an Image control that renders a bitmap. all this is inside a ScrollViewer control and I'm trying to manipulate its offset
javidx9
YouTube
Programming Panning & Zooming
A genuinely practical video today! In this video, I take a look at a really useful technique to easily add panning and zooming to your applications. Source: https://github.com/OneLoneCoder/Javidx9/blob/master/ConsoleGameEngine/SmallerProjects/OneLoneCoder_PanAndZoom.cpp https://discord.gg/WhwHUMV Blog: http://www.onelonecoder.com Twitter: @jav...
Stack Overflow
Zoom in on a point (using scale and translate)
I want to be able to zoom in on the point under the mouse in an HTML 5 canvas, like zooming on Google Maps. How can I achieve that?
No description
5 Replies
ティナ
ティナ2w ago
The better solution is to simply move the position of the viewport based on the change in the zoom. The zoom point is simply the point in the old zoom and the new zoom that you want to remain the same. Which is to say the viewport pre-zoomed and the viewport post-zoomed have the same zoompoint relative to the viewport. Given that we're scaling relative to the origin. You can adjust the viewport position accordingly:
scalechange = newscale - oldscale;
offsetX = -(zoomPointX * scalechange);
offsetY = -(zoomPointY * scalechange);
scalechange = newscale - oldscale;
offsetX = -(zoomPointX * scalechange);
offsetY = -(zoomPointY * scalechange);
have you tried this first? btw i use different strategy and it may a bit complicated than this one i didnt use <Transform> but binding to a view model that containing the scale and the bounding box
Hermes
HermesOP2w ago
I've actually sorted it out mostly
No description
Hermes
HermesOP2w ago
But the issue now is that the ScrollViewer's Extent doesn't change with respect to the scaling, so the canvas is basically being clipped when I zoom in
No description
Hermes
HermesOP2w ago
Trying to find a way to make it recalculate it's Extent Since the Border control is being scaled, its dimensions should change and the ScrollViewer should adapter (basically expand/compress) to fit the Border control Or perhaps I'll have to remove the ScrollViewer and manually do the panning for better control over all this stuff :LETSFUCKINGTHINK:
ティナ
ティナ2w ago
i use <Canvas> since it supports absolute (css way) position

Did you find this page helpful?