protected override RequestedAction LayoutImage(ImageState s) { //Only activated if both width and height are specified, and mode=crop. if (s.settings.Mode != FitMode.Crop || s.settings.Width < 0 || s.settings.Height < 0) { return(RequestedAction.None); } var finalMode = s.settings.Get("c.finalmode", FitMode.Pad); var regions = SalientArea.FromQuery(s.settings); if (regions.Length == 0) { return(RequestedAction.None); } var a = new Aligner { Regions = regions, ImageSize = s.originalSize, TargetSize = new Size(s.settings.Width, s.settings.Height), NeverCropSalientArea = finalMode != FitMode.Crop, Zoom = regions[0].Area.Width > 0 && regions[0].Area.Height > 0 && s.settings.Get("c.zoom", false) }; s.copyRect = a.GetCrop(); s.ValidateCropping(); //So, if we haven't met the aspect ratio yet, what mode will we pass on? s.settings.Mode = finalMode; return(RequestedAction.None); }