public FCrop(ChangeTracker changeTracker) { this.changeTracker = changeTracker; InitializeComponent(); CropTransform = new CropTransform(); }
protected override void ResetTransform() { CropTransform = new CropTransform { OriginalHeight = originalHeight, OriginalWidth = originalWidth }; }
public FCrop(ChangeTracker changeTracker, ThumbnailRenderer thumbnailRenderer) { this.changeTracker = changeTracker; this.thumbnailRenderer = thumbnailRenderer; InitializeComponent(); CropTransform = new CropTransform(); }
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); }
public void FromPercentages() { var crop = CropTransform.Parse("crop(50%,50%,960,540)"); Assert.Equal(Unit.Percent(50), crop.X); Assert.Equal(Unit.Percent(50), crop.Y); Assert.Equal(960, crop.Width); Assert.Equal(540, crop.Height); Assert.Equal("crop(50%,50%,960,540)", crop.ToString()); }
public void B() { var crop = CropTransform.Parse("crop(x:0,y:0,width:960,height:540)"); Assert.Equal(0d, crop.X); Assert.Equal(0d, crop.Y); Assert.Equal(960, crop.Width); Assert.Equal(540, crop.Height); Assert.Equal("crop(0,0,960,540)", crop.ToString()); }
private void UpdateTransform() { CropTransform = new CropTransform { Left = Math.Min(tbLeft.Value, tbRight.Value), Right = originalWidth - Math.Max(tbLeft.Value, tbRight.Value), Bottom = Math.Min(tbTop.Value, tbBottom.Value), Top = originalHeight - Math.Max(tbTop.Value, tbBottom.Value), OriginalHeight = originalHeight, OriginalWidth = originalWidth }; UpdatePreviewBox(); }
protected override void InitTransform() { originalWidth = workingImage.Width; originalHeight = workingImage.Height; if (_lastTransform != null && _lastSize == workingImage.Size) { CropTransform = _lastTransform; } else { ResetTransform(); } UpdateCropBounds(); lm.UpdateLayout(); }
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 = new CropTransform { Right = (int)((width - (float)pageDimensions.HeightInInches()) * output.HorizontalResolution), Bottom = (int)((height - (float)pageDimensions.WidthInInches()) * output.VerticalResolution) }.Perform(result); // result.SetResolution((float)(output.Width / pageDimensions.HeightInInches()), (float)(output.Height / pageDimensions.WidthInInches())); } else { result = new CropTransform { Right = (int)((width - (float)pageDimensions.WidthInInches()) * output.HorizontalResolution), Bottom = (int)((height - (float)pageDimensions.HeightInInches()) * output.VerticalResolution) }.Perform(result); //result.SetResolution((float)(output.Width / pageDimensions.WidthInInches()), (float)(output.Height / pageDimensions.HeightInInches())); } } return(result); }
private void btnRevert_Click(object sender, EventArgs e) { CropTransform = new CropTransform(); UpdatePreviewBox(); }
protected override void TransformSaved() { _lastTransform = CropTransform; _lastSize = workingImage.Size; }