Created
September 15, 2015 10:26
-
-
Save Larry57/ae06d979987d07677483 to your computer and use it in GitHub Desktop.
Calculate a zoom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sourceSize = source control size | |
// targetSize = target control size | |
// center of the zoom | |
// zoom radius | |
static Rectangle Zoom(Size sourceSize, Size targetSize, Point center, int radius) | |
{ | |
var f = Math.Min((double)targetSize.Width / ((double)radius * 2d), (double)targetSize.Height / ((double)radius * 2d)); | |
var loc = new Point((int)((-center.X + radius) * f), (int)((-center.Y + radius) * f)); | |
var size = new Size((int)(sourceSize.Width * f), (int)(sourceSize.Height * f)); | |
loc.X += (int)(((double)targetSize.Width - (double)radius * f * 2d) / 2d); | |
loc.Y += (int)(((double)targetSize.Height - (double)radius * f * 2d) / 2d); | |
return new Rectangle(loc, size); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment