I am creating an image resizer method to fit an image to a maximum size (max-width and max-height). I'm using following method to calculate target dimensions. If width is bigger than max-width, I set the width to max-width and calculate height and then, do this again for height, by using this simple math formulla: 

> 
> (width / height) = (maxWidth / maxHeight)
> 
> 
> 

But, resized image seems has not correct dimensions when it got resized. My method is this:

```
private static Size CalculateDimensions(Size currentSize, double maxWidth, double maxHeight) {            
    double width = currentSize.Width,
           height = currentSize.Height;
    if (width > maxWidth) {
        width = maxWidth;
        height = width * maxHeight / maxWidth;
    }
    if (height > maxHeight) {
        height = maxHeight;
        width = height * maxWidth / maxHeight;
    }
    return new Size(Convert.ToInt32(width), Convert.ToInt32(height));   
}

```

Can you tell me where am I wrong? Why this doesn't work?