コード例 #1
0
        public System.IO.Stream CropSquareImage(System.IO.Stream imageStream)
        {
            #region validation

            if (imageStream == null)
            {
                throw new ArgumentNullException(nameof(imageStream));
            }

            #endregion

            // get original size of image
            Rect imageDimension = ImageUtil.GetDimensionFromImage(imageStream);

            if (imageDimension.IsHorizontalFormat())
            {
                // widht is greater then height --> height is leading information
                // returns image with dimension: height*height
                // left and right will be cropped
                return(GetImageDetail(imageStream, (imageDimension.Width - imageDimension.Height) / 2, 0, imageDimension.Height, imageDimension.Height));
            }
            else if (imageDimension.IsVerticalFormat())
            {
                // height is greater then width --> width is leading information
                // return image with dimension: widht*width
                // top and bottom will be croped
                return(GetImageDetail(imageStream, 0, (imageDimension.Height - imageDimension.Width) / 2, imageDimension.Width, imageDimension.Width));
            }

            // heigth and widht are equal
            // image will be returned as copy
            return(imageStream.CopyStream());
        }
コード例 #2
0
        public System.IO.Stream FillSquareImage(System.IO.Stream imageStream, string fillColor)
        {
            Rect imageDimension = ImageUtil.GetDimensionFromImage(imageStream);

            if (imageDimension.IsSquare())
            {
                // heigth and widht are equal
                // image will be returned as copy
                return(imageStream.CopyStream());
            }

            int squareSize = Math.Max(imageDimension.Height, imageDimension.Width);

            return(FillImage(imageStream, fillColor, squareSize, squareSize));
        }