1
Vote

ResizeMethod.AspectRatioFill issue

description

protected virtual Size GetNewSize(Image img, Size requestedSize, ResizeMethod method, out Size bitmapSize)
    {
        Size outputSize = new Size();

        switch (method)
        {
            case ResizeMethod.AspectRatioFill:
                {

                    float ratio = (float)img.Width / (float)img.Height;


                    float reqRatio = (float)requestedSize.Width / (float)requestedSize.Height;
                    if (ratio > reqRatio)
                    {
                        outputSize.Height = (int) ((float) requestedSize.Width/ratio);
                        outputSize.Width = requestedSize.Width;

                    }
                    else
                    {
                        outputSize.Width = (int)((float)requestedSize.Height * ratio);
                        outputSize.Height = requestedSize.Height;
                    }


                } break;

comments