Пример #1
0
        public static Bitmap PostProcessStep1(Image output, ScanProfile profile)
        {
            double scaleFactor = 1;

            if (!profile.UseNativeUI)
            {
                scaleFactor = profile.AfterScanScale.ToIntScaleFactor();
            }
            var result = ImageScaleHelper.ScaleImage(output, scaleFactor);

            if (!profile.UseNativeUI && profile.ForcePageSize)
            {
                float width  = output.Width / output.HorizontalResolution;
                float height = output.Height / output.VerticalResolution;
                if (float.IsNaN(width) || float.IsNaN(height))
                {
                    width  = output.Width;
                    height = output.Height;
                }
                PageDimensions pageDimensions = profile.PageSize.PageDimensions() ?? profile.CustomPageSize;
                if (pageDimensions.Width > pageDimensions.Height && width < height)
                {
                    // Flip dimensions
                    result.SetResolution((float)(output.Width / pageDimensions.HeightInInches()), (float)(output.Height / pageDimensions.WidthInInches()));
                }
                else
                {
                    result.SetResolution((float)(output.Width / pageDimensions.WidthInInches()), (float)(output.Height / pageDimensions.HeightInInches()));
                }
            }

            return(result);
        }
Пример #2
0
        public Bitmap PostProcessStep1(Image output, ScanProfile profile, bool supportsNativeUI = true)
        {
            double scaleFactor = 1;

            if (!profile.UseNativeUi || !supportsNativeUI)
            {
                scaleFactor = profile.AfterScanScale.ToIntScaleFactor();
            }
            var result = ImageScaleHelper.ScaleImage(output, scaleFactor);

            if ((profile.UseNativeUi && supportsNativeUI) || (!profile.ForcePageSize && !profile.ForcePageSizeCrop))
            {
                return(result);
            }
            var width  = output.Width / output.HorizontalResolution;
            var height = output.Height / output.VerticalResolution;

            if (float.IsNaN(width) || float.IsNaN(height))
            {
                width  = output.Width;
                height = output.Height;
            }
            var pageDimensions = profile.PageSize.PageDimensions() ?? profile.CustomPageSize;

            if (pageDimensions.Width > pageDimensions.Height && width < height)
            {
                if (profile.ForcePageSizeCrop)
                {
                    result = new CropTransform
                    {
                        Right  = (int)((width - (float)pageDimensions.HeightInInches()) * output.HorizontalResolution),
                        Bottom = (int)((height - (float)pageDimensions.WidthInInches()) * output.VerticalResolution)
                    }.Perform(result);
                }
                else
                {
                    result.SafeSetResolution((float)(output.Width / pageDimensions.HeightInInches()),
                                             (float)(output.Height / pageDimensions.WidthInInches()));
                }
            }
            else
            {
                if (profile.ForcePageSizeCrop)
                {
                    result = new CropTransform
                    {
                        Right  = (int)((width - (float)pageDimensions.WidthInInches()) * output.HorizontalResolution),
                        Bottom = (int)((height - (float)pageDimensions.HeightInInches()) * output.VerticalResolution)
                    }.Perform(result);
                }
                else
                {
                    result.SafeSetResolution((float)(output.Width / pageDimensions.WidthInInches()), (float)(output.Height / pageDimensions.HeightInInches()));
                }
            }

            return(result);
        }