public void Decorate(ImageDecoratorContext context) { CropDecoratorSettings settings = new CropDecoratorSettings(context.Settings); //ImageUtils.AdjustBrightness(bsettings.Brightness, bsettings.Contrast, context.Image); Rectangle?rect = settings.CropRectangle; // only do the following if polaroid is active if (context.EnforcedAspectRatio != null) { float aspectRatio = context.EnforcedAspectRatio.Value; RotateFlipType flip; if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert || context.InvocationSource == ImageDecoratorInvocationSource.Reset) { flip = ImageUtils.GetFixupRotateFlipFromExifOrientation(context.Image); } else { flip = context.ImageRotation; } if (ImageUtils.IsRotated90(flip)) { aspectRatio = 1 / aspectRatio; } rect = RectangleHelper.EnforceAspectRatio(rect ?? new Rectangle(Point.Empty, context.Image.Size), aspectRatio); } if (rect != null) { Bitmap cropped = ImageHelper2.CropBitmap(context.Image, (Rectangle)rect); try { PropertyItem orientation = context.Image.GetPropertyItem(0x112); if (orientation != null) { cropped.SetPropertyItem(orientation); } } catch (ArgumentException) { // orientation data was not present } context.Image = cropped; } }
public void AdjustOriginalSize(IProperties properties, ref Size size) { size = RectangleHelper.EnforceAspectRatio(new Rectangle(Point.Empty, size), PortalAspectRatio).Size; }
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); } }