Jump to content
  • Advertisement
Sign in to follow this  
Ructions

[.net] Zoom In

This topic is 5039 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

I am using C# and was wondering how can you zoom in on a image that is placed in a picture box. i want to be able to click on the image in the picturebox and the position i click at the image centers at that position in the picturebox at the location i clicked at and zooms in. thanks in advance ructions

Share this post


Link to post
Share on other sites
Advertisement
An idea might be to do a simple bit of geometry so that depending on

1) the origin of the zoom, ie where it was clicked, or the centr eof the image or whatever
2) zoom factor

you can simply define the new texture coordinates for the surface it is being rendered to and then re-render the texture to the surface.

ace

Share this post


Link to post
Share on other sites
To scale an image in a PictureBox:

1)Create a new Bitmap of the desired size.
2)Create a Graphics object on the bitmap.
3)Call DrawImage(image,srcRect,destRect,GraphicsUnit.Pixel) on the graphics object, where the srcRect is the area to zoom and the destRect is the target bitmap's size.
4)Set the PictureBox.Image to new bitmap.

To figure out your srcRect try something like this (psudocode):

//apply a zoom factor
srcRect.Width = viewArea.Width * (1/zoomFactor);
srcRect.Height = viewArea.Height * (1/zoomFactor);
//center it to the mouse
srcRect.X = srcRect.Width/2 + mouse.X;
srcRect.Y = srcRect.Height/2 + mouse.Y;



hope this helps.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!