Пример #1
0
        public static AdjustedSizesResult AdjustSizes(Bitmap bitmap, int dimension, ResizeType resizeType)
        {
            AdjustedSizesResult adjustedSizes = new AdjustedSizesResult();

            if (resizeType == ResizeType.MinDimension)
            {
                int relatedDimension = 0;
                adjustedSizes.Resize = true;

                if (bitmap.Height > bitmap.Width)
                {
                    adjustedSizes.Width  = dimension;
                    adjustedSizes.Height = Convert.ToInt32((double)bitmap.Height / ((double)bitmap.Width / (double)dimension));
                    relatedDimension     = bitmap.Width;
                }
                else
                {
                    adjustedSizes.Height = dimension;
                    adjustedSizes.Width  = Convert.ToInt32((double)bitmap.Width / ((double)bitmap.Height / (double)dimension));
                    relatedDimension     = bitmap.Height;
                }

                if (relatedDimension <= dimension)
                {
                    adjustedSizes.Resize = false;
                }
            }
            else
            {
                int relatedDimension = 0;
                adjustedSizes.Resize = true;

                if (bitmap.Height < bitmap.Width)
                {
                    adjustedSizes.Width  = dimension;
                    adjustedSizes.Height = Convert.ToInt32((double)bitmap.Height / ((double)bitmap.Width / (double)dimension));
                    relatedDimension     = bitmap.Width;
                }
                else
                {
                    adjustedSizes.Height = dimension;
                    adjustedSizes.Width  = Convert.ToInt32((double)bitmap.Width / ((double)bitmap.Height / (double)dimension));
                    relatedDimension     = bitmap.Height;
                }

                if (relatedDimension <= dimension)
                {
                    adjustedSizes.Resize = false;
                }
            }

            return(adjustedSizes);
        }
Пример #2
0
        public static AdjustedSizesResult AdjustSizes(Bitmap bitmap, int width, int height)
        {
            AdjustedSizesResult adjustedSizes = new AdjustedSizesResult();

            adjustedSizes.Resize = true;

            if (width == 0 || height == 0)
            {
                if (height == 0)
                {
                    adjustedSizes.Width  = width;
                    adjustedSizes.Height = Convert.ToInt32((double)bitmap.Height / ((double)bitmap.Width / (double)width));
                }
                else
                {
                    adjustedSizes.Height = height;
                    adjustedSizes.Width  = Convert.ToInt32((double)bitmap.Width / ((double)bitmap.Height / (double)height));
                }
            }

            return(adjustedSizes);
        }