Jump to content
  • Advertisement
Sign in to follow this  

zoom in/out in using Drawing.Graphics

This topic is 2584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey boys and girls, I've been struggling with this second day in a row so I do need help...
The situation:
Am using winForm;
In winForm I have panel or pictureBox;
Create a graphics out of them (i.e. panel.createGraphics());
Draw a bunch of lines and images using graphics.draw();
Now I want to zoom in and get it centralized;

Currently I am using graphics.scaleTransfrom() and even though it does gives me zoom in\out I can't seem find a way to make the center of the image in the center of control.

When using scaleTransform the coordinates doesn't change of draw figures so can't play with them..

Hope I explained it in understandable manner. ;)

To put it simply:
How to draw graphics in the center when using scaleTransform?
Is there a better approach to it?
I need precision (lines have to be float type);

Share this post

Link to post
Share on other sites

TranslateTransform by (-cx, -cy) so that the centre is located at the origin, then scale, then translate back.

Thanks, worked like a charm:

//move center point to center of image
gfx.TranslateTransform(pictureBox1.Width / 2, pictureBox1.Height / 2);
gfx.ScaleTransform(imageScale, imageScale);
//move image back
gfx.TranslateTransform(-pictureBox1.Width / 2, -pictureBox1.Height / 2);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!