I'm creating an image editing program in GTK\C, and I can't figure out how to make zoom work; I need to zoom my Cairo-based canvas to the mouse cursor's position, but Cairo only zooms to center of the image it displays. The normal way to get around this is to transform, zoom, and then transform back; but that messes up the scrollbars surrounding my canvas.
My idea was to slide the scrollbars back to compensate for the movement caused by zooming. Moving the scrollbars by mouse_position * (new_zoom - old_zoom) ought to work, but it doesn't; it under-corrects at low zoom levels, then over-corrects at high levels.
How can I zoom correctly?
My code is visible here, if it helps: ScreenSnap on Github
It looks like you need to scale your shift to your current zoom level in the code. So this line:
shift_x = self->zoom_point_x * (self->zoom_level / .9 - self->zoom_level);
Should be:
shift_x = self->zoom_point_x * (self->zoom_level / .9 - self->zoom_level)/(self->zoom_level);
Note that your approximation worked at a zoom level of one but as you move away you either under or overcorrect.
Related
I am trying to implement zoom in zoom out functionality in VC++ MFC framework.As I am new for this facing problem in CDC, Graphics And CscrollView concepts.
Default ZoomLevel is 100% and it's scaling by 20% up/Down (60,80,100,120,140,160).
As I have to Zoom the CRect (i.e some rectangular blocks) along with that some lines which is connected to that Rectangle.
Currently Able to zoom with scrollbar support using Cscrollview but while we zoom at some level for ex. 120% I am expanding canvas size
canvas default page size vertically and horizontally are i.e 5000.
Now while we zoom #120% (canvas size * 120) i.e 6000.
Anyhow after zooming blocks and inside image all are expands properly at all zoom level. But the main problem is Connecter With that rectangle block are
not exactly connected to center its showing some gap.
For that I am attaching one image which showing gap between Block and Connector line.
Before Zoom # default level i.e 100% which looks properly connected:
After Doing zoomin i.e #120% Lines are not connected properly to the Blocks:
As you can see Before and after Zoom rectangle and lines objects showing some gap.That is required to be fixed after doing zoomin/out.
Please let me know, What should be best practise or how to expand/zoom the canvas and its all the objects on it ?
Is there any way if we expand or zoom the view/canvas bitmap object all the object(CREct + Lines + images etc on that canvas also adjusted accordingly?
My requirement for zoomin/zoomout is similar like windows print preview dialog box is providing DefaultView Zoomin and Zoomout option at diffrent level (100,125,150,200 etc).
Or if you have any project reference code related to this please share it will be very big help for me.
i am trying to use the combined camera (found it under "Examples").
the problem is when i use it in Orthographic mode i still see the arrow and the box helper like in perspective view.
for example, when i am trying to zoom in with the mouse scroll, i can see the plane in the same size (as it supposed to be in orthographic view) but the arrows and the small box between the arrows is getting smaller or bigger.
when i tried to debug it at the renderer function i saw the camera is still in orthograpic mode when it render the arrows.
any idea how can i make all the object to be in orthograpic view but still use the combined camera?
edit:
i am not sure which part of the code i should post so i add a picture to describe my problem.
you can see that i am in an orthographic camera and i'm trying to zoom in and i can see the axis arrow getting bigger or smaller.
the difference between the plane when zooming
Found a possible answer which worked for me:
under TransformControls.js
change the update function to:
scale = (camera.inOrthographicMode == true)? 100 : worldPosition.distanceTo(camPosition ) / 6 * scope.size;
I am trying to use the new 4.6 Unity GUI system to create a bit of UI. I want to make this UI at a resolution of 400x300, then render to a texture which will then be drawn to the screen at a resolution of 800x600 (so double resolution). The problem is this: It doesn't work. The rendering is okay and I can correctly upscale the render texture and have it drawn to the screen, but the UI events aren't received in the correct position, and I can find no way to get around this.
So:
Player resolution is 800x600 Render texture resolution is 400x300
Main camera, called "UI Camera" renders to this texture (at 400x300)
Canvas set to "Screen Space - Camera" pointing at "UI Camera". Under this is a button which is set to stretch to all sides (so fullscreen, 400x300)
A second camera, called "Upscaling Camera".
Another canvas set to "Screen Space - Camera" pointing at "Upscaling Camera".
This canvas has it's GraphicRaycaster component removed. Under this is a RawImage displaying the render texture.
When I play, the UI is correctly rendered to the rendertexture, and then displayed on screen at 2x resolution, filling the screen. What is not working is the events - the button can only be interacted with when the mouse is in the lower-left quarter of the screen.
Conceptually, this makes sense. The button is occupying a space from (0, 0) to (400, 300) (starting at the bottom left of the screen), and now my player's resolution is 800x600, this rectangle only covers the bottom left corner. I get that.
So, with all that said, what can I do to fix this? I can't set the EventCamera on the GraphicRaycaster, so that's out. My next thought was to be somehow fudging the mouse positions. But honestly, I have no clue where to go.
(And in case somebody has a better way of doing this - I'm looking at a game working in 400x300 resolution which needs to be pixel-perfect. If I were to resize all my UI externally, that would mean that in-engine, they are essentially running on a half-pixel grid. Same goes for using the CanvasScaler component.)
Cheers for any help.
Does anyone know how to zoom/pan (scroll) on the imagebox of EmguCV using C# code? It works just fine using mouse scroll, But I'd like to do it using code.
I tried this, but with no luck!
ImageBox1.SetZoomScale(1, new Point(400, 400));
With SetZoomScale you are on the right way.
Set a zoom scale grater than 1 to zoom in and a zoom scale smaller than 1 to zoom out. 1 means no zoom.
The second parameter is the center of the zoomed area relative to the image control.
So, if you start with a ZoomScale = 1 do the following:
Zoom in with fix point (400,00)
ImageBox1.SetZoomScale(2, new Point(400, 400));
Reset original zoom
ImageBox1.SetZoomScale(1, new Point(400, 400));
Zoom out with fix point (400,00)
ImageBox1.SetZoomScale(0.5, new Point(400, 400));
I'm have a picture box control and 2 Command Buttons. I have an image displayed inside the picture box.
Is it possible to zoom the image when the Zoom-in and Zoom out buttons are clicked?
Or I can even put a scroll bar. Is it possible to zoom the image according to the scroll bar movements?
I'm using VB 6.
I assume here that you are using BMP or JPG files here.
The simple scratch method is to place an Image control in the PictureBox, initially with the property Stretch = False. Initially, it would be in the top left hand corner. After setting the Picture property to your picture object, the Image control will be resized to fit the image. Save the original width and height of the control in variables. Now set Stretch = True. You can zoom in by resizing the image using
img.Move 0, 0, sngWidth * sngMagFactor, sngHeight * sngMagFactor
Where sngMaxFactor = 4! or however much you want to zoom by.
Restore back to original size by:
img.Move 0, 0, sngWidth, sngHeight
You can also pan the zoomed image by altering the Left and Top arguments in the Move() method.
It might be easiest to use two pic boxes, one inside the other. The 'outer' box can be thought of as a viewport into the 'inner' box, which you resize and position as needed. The effect will be the same but the coding is much simpler.