コード例 #1
0
        /// <summary>
        /// The width of the object can be more than the diameter of the base disc
        /// In such scenarios, we will need to keep some extra padding on each side of disc
        /// while cropping the image. This function calculates the amount by which we should pad.
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        public static double GetExtraPadding(CreateMeshContract contract)
        {
            var maxExtraPaddingPercent = 0.0;
            var bottomPaddingPercent   = contract.BottomPaddingPercent;

            //for each image
            foreach (var clickInput in contract.ClickInputs.ImageClickInputDetailsList)
            {
                var imageName = clickInput.ImageName;

                var bitmapImg = (Bitmap)Image.FromFile(string.Format(@"{0}\{1}", contract.ImageFolder, imageName));

                //resize to 100 (small size)
                const int newWidth  = 100;
                var       newHeight = newWidth * bitmapImg.Height / bitmapImg.Width;

                var imageAlterationParams = new ImageAlterationParams
                {
                    ResizeType           = ResizeType.ToSpecifiedSizes,
                    SpecificResizeHeight = newHeight,
                    SpecificResizeWidth  = newWidth
                };

                var resizedImage = ImageResizer.ResizeImage(bitmapImg, imageAlterationParams);

                //strip background
                BackgroundStripper.StripBackground(resizedImage, contract.BackgroundStrippingParams);

                //get actual borders for this image
                var origImageCorners   = ImageCorners.GetImageCornersFromClickInputs(clickInput, contract.MinImageHeightRatio, bottomPaddingPercent);
                var actualImageCorners = ImageCorners.GetActualImageCorners(origImageCorners, resizedImage, clickInput.ClickPositionListForImages);

                //calculate extra padding percent
                var padding = ExtraPadding.GetExtraPaddingPercent(resizedImage, actualImageCorners,
                                                                  contract.InvalidColor);

                //check if it is more than the maximum so far
                if (maxExtraPaddingPercent < padding)
                {
                    maxExtraPaddingPercent = padding;
                }
            }
            return(maxExtraPaddingPercent);
        }
コード例 #2
0
        private static Bitmap GetRotatedCroppedResizedAndStrippedImage(BackgroundStrippingParams strippingParams, ImageClickInputDetails clickInput, ImageAlterationParams imageAlterationParams)
        {
            //pickup image from the source location
            var image = (Bitmap)Image.FromFile(String.Format(@"{0}\{1}", imageAlterationParams.ImageFolder, clickInput.ImageName));

            //rotate
            image = MainProcessor.RotateImg(image, (float)clickInput.RotateImageBy, imageAlterationParams.InvalidColor);

            //crop
            image = ImageCropper.GetCroppedImage(clickInput, image, imageAlterationParams);

            //resize
            image = ImageResizer.ResizeImage(image, imageAlterationParams);

            //strip background
            BackgroundStripper.StripBackground(image, strippingParams);

            return(image);
        }
コード例 #3
0
 public static Bitmap ResizeJpg(string sourceFileName, string destinationFileName, int width, int height)
 {
     return(ImageResizer.ResizeJpg(sourceFileName, destinationFileName, width, height));
 }
コード例 #4
0
 public static Bitmap ResizeImage(Bitmap image, ImageAlterationParams imageAlterationParams)
 {
     return(ImageResizer.ResizeImage(image, imageAlterationParams));
 }