protected override void LoadEditor() { bitmap = (Bitmap)State; Size origSize = bitmap.Size; bitmap.RotateFlip(EditorContext.ImageRotation); imageCropControl.Bitmap = bitmap; ((AspectRatioItem)cbAspectRatio.Items[0]).AspectRatio = bitmap.Width / (double)bitmap.Height; CropDecoratorSettings settings = new CropDecoratorSettings(Settings); originalState = settings.CreateStateToken(); Rectangle?cropRectangle = settings.CropRectangle; if (EditorContext.EnforcedAspectRatio != null) { Rectangle rect; if (cropRectangle != null) { rect = RectangleHelper.RotateFlip(origSize, cropRectangle.Value, EditorContext.ImageRotation); } else { rect = new Rectangle(Point.Empty, bitmap.Size); } rect = RectangleHelper.EnforceAspectRatio(rect, EditorContext.EnforcedAspectRatio.Value); imageCropControl.CropRectangle = rect; imageCropControl.AspectRatio = EditorContext.EnforcedAspectRatio.Value; } else if (cropRectangle != null) { string savedAspectRatioId = settings.AspectRatioId; double?savedAspectRatio = settings.AspectRatio; if (savedAspectRatioId != null) { foreach (AspectRatioItem item in cbAspectRatio.Items) { if (item.Id == savedAspectRatioId) { // doubles can't be accurately compared after they've been round-tripped // to strings, due to lossy conversion to/from strings. if ((float)(item.AspectRatio ?? 0.0) != (float)(savedAspectRatio ?? 0.0)) { if (item.AspectRatio == null || savedAspectRatio == null) { continue; } if (item.AspectRatio.Value != 1 / savedAspectRatio.Value) { continue; } } cbAspectRatio.SelectedItem = item; imageCropControl.AspectRatio = savedAspectRatio; break; } } } if (cbAspectRatio.SelectedIndex == -1) { cbAspectRatio.SelectedIndex = 1; } imageCropControl.CropRectangle = RectangleHelper.RotateFlip(origSize, cropRectangle.Value, EditorContext.ImageRotation); } else { cbAspectRatio.SelectedIndex = 1; UpdatePreview(true); } }