protected override void LoadEditor() { base.LoadEditor(); ImageResizeSettings = new HtmlImageResizeDecoratorSettings(Settings, EditorContext.ImgElement); Size imageSize = ImageResizeSettings.ImageSize; sizeCommand.Value = imageSize; if (EditorContext.SourceImageSize == new Size(Int32.MaxValue, Int32.MaxValue)) { //The source image size is unknown, so calculate the actual image size by removing //the size attributes, checking the size, and then placing the size attributes back object oldHeight = EditorContext.ImgElement.getAttribute("height", 2); object oldWidth = EditorContext.ImgElement.getAttribute("width", 2); EditorContext.ImgElement.removeAttribute("width", 0); EditorContext.ImgElement.removeAttribute("height", 0); int width = ((IHTMLImgElement)EditorContext.ImgElement).width; int height = ((IHTMLImgElement)EditorContext.ImgElement).height; if (oldHeight != null) { EditorContext.ImgElement.setAttribute("height", oldHeight, 0); } if (oldWidth != null) { EditorContext.ImgElement.setAttribute("width", oldWidth, 0); } imageSizeControl.LoadImageSize(imageSize, new Size(width, height), EditorContext.ImageRotation); } else { imageSizeControl.LoadImageSize(imageSize, EditorContext.SourceImageSize, EditorContext.ImageRotation); } }
void IImageDecoratorDefaultSettingsCustomizer.CustomizeDefaultSettingsBeforeSave(ImageDecoratorEditorContext context, IProperties defaultSettings) { //clear all defaulted settings for this decorator foreach (string key in defaultSettings.Names) { defaultSettings.Remove(key); } HtmlImageResizeDecoratorSettings defaultResizeSettings = new HtmlImageResizeDecoratorSettings(defaultSettings, context.ImgElement); HtmlImageResizeDecoratorSettings resizeSettings = new HtmlImageResizeDecoratorSettings(context.Settings, context.ImgElement); //explicitly save the settings we want to support defaulting for. defaultResizeSettings.DefaultBoundsSizeName = resizeSettings.ImageSizeName; if (resizeSettings.ImageSizeName == ImageSizeName.Custom) { defaultResizeSettings.DefaultBoundsSize = resizeSettings.ImageSize; } }
void IImageDecoratorDefaultSettingsCustomizer.CustomizeDefaultSettingsBeforeSave(ImageDecoratorEditorContext context, IProperties defaultSettings) { //clear all defaulted settings for this decorator foreach (string key in defaultSettings.Names) defaultSettings.Remove(key); HtmlImageResizeDecoratorSettings defaultResizeSettings = new HtmlImageResizeDecoratorSettings(defaultSettings, context.ImgElement); HtmlImageResizeDecoratorSettings resizeSettings = new HtmlImageResizeDecoratorSettings(context.Settings, context.ImgElement); //explicitly save the settings we want to support defaulting for. defaultResizeSettings.DefaultBoundsSizeName = resizeSettings.ImageSizeName; if (resizeSettings.ImageSizeName == ImageSizeName.Custom) { defaultResizeSettings.DefaultBoundsSize = resizeSettings.ImageSize; } }
public void Decorate(ImageDecoratorContext context) { bool useOriginalImage = true; HtmlImageResizeDecoratorSettings settings = new HtmlImageResizeDecoratorSettings(context.Settings, context.ImgElement); if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert || context.InvocationSource == ImageDecoratorInvocationSource.Reset) { // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. // If ImageSizeName is set, then use that instead of default values if (settings.IsImageSizeNameSet && context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert) { // We must be copying settings from another instance of the same image settings.SetImageSize(settings.ImageSize, settings.ImageSizeName); // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. // Also if we are copying settings, then use the image instance from context instead of the // original image. This ensures we use the cropped image (if any) to resize. useOriginalImage = false; } else { //calculate the default image size and rotation. If the camera has indicated that the //orientation of the photo is rotated (in the EXIF data), shift the rotation appropriately //to insert the image correctly. //Fix the image orientation based on the Exif data (added by digital cameras). RotateFlipType fixedRotation = ImageUtils.GetFixupRotateFlipFromExifOrientation(context.Image); settings.Rotation = fixedRotation; settings.BaseSize = context.Image.Size; //the default size is a scaled version of the image based on the default inline size constraints. Size defaultBoundsSize; if (settings.DefaultBoundsSizeName != ImageSizeName.Full) { defaultBoundsSize = settings.DefaultBoundsSize; } else //original size is default, so we aren't going to scale { defaultBoundsSize = context.Image.Size; } //calulate the base image size to scale from. If the image is rotated 90 degrees, then switch the height/width Size baseImageSize = context.Image.Size; if (ImageUtils.IsRotated90(settings.Rotation)) baseImageSize = new Size(baseImageSize.Height, baseImageSize.Width); //calculate and set the scaled default size using the defaultSizeBounds //Note: if the image dimensions are smaller than the default, don't scale that dimension (bug 419446) Size defaultSize = ImageUtils.GetScaledImageSize(Math.Min(baseImageSize.Width, defaultBoundsSize.Width), Math.Min(baseImageSize.Height, defaultBoundsSize.Height), baseImageSize); if (defaultSize.Width < defaultBoundsSize.Width && defaultSize.Height < defaultBoundsSize.Height) settings.SetImageSize(defaultSize, ImageSizeName.Full); else settings.SetImageSize(defaultSize, settings.DefaultBoundsSizeName); } } else if (settings.BaseSizeChanged(context.Image)) { Size newBaseSize = context.Image.Size; settings.SetImageSize(AdjustImageSizeForNewBaseSize(true, settings, newBaseSize, settings.Rotation, context), null); settings.BaseSize = newBaseSize; } //this decorator only applies to embedded images. if (context.ImageEmbedType == ImageEmbedType.Embedded && !ImageHelper2.IsAnimated(context.Image)) { Bitmap imageToResize = null; // To make image insertion faster, we've already created an initial resized image on a background thread. if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert && useOriginalImage) { try { string imageSrc = context.ImgElement.getAttribute("src", 2) as string; if (!string.IsNullOrEmpty(imageSrc) && (UrlHelper.IsFileUrl(imageSrc) || File.Exists(new Uri(imageSrc).ToString()))) { Uri imageSrcUri = new Uri(imageSrc); imageToResize = (Bitmap)Image.FromFile(imageSrcUri.LocalPath); } } catch (Exception e) { Debug.Write("Failed to load pre-created initial image: " + e); } } if (imageToResize == null) imageToResize = context.Image; // Figure the desired image size by taking the size of the img element // and calculate what borderless image size we'd need to start with // to end up at that size. This is different than simply subtracting // the existing border size, since borders can be relative to the // size of the base image. Size desiredImageSize = settings.BorderMargin.ReverseCalculateImageSize(settings.ImageSizeWithBorder); //resize the image and update the image used by the context. if (desiredImageSize != imageToResize.Size || settings.Rotation != RotateFlipType.RotateNoneFlipNone) { context.Image = ResizeImage(imageToResize, desiredImageSize, settings.Rotation); } else { context.Image = imageToResize; } if (settings.ImageSize != context.Image.Size) settings.SetImageSize(context.Image.Size, settings.ImageSizeName); } }
protected override void LoadEditor() { base.LoadEditor(); ImageResizeSettings = new HtmlImageResizeDecoratorSettings(Settings, EditorContext.ImgElement); Size imageSize = ImageResizeSettings.ImageSize; sizeCommand.Value = imageSize; if (EditorContext.SourceImageSize == new Size(Int32.MaxValue, Int32.MaxValue)) { //The source image size is unknown, so calculate the actual image size by removing //the size attributes, checking the size, and then placing the size attributes back object oldHeight = EditorContext.ImgElement.getAttribute("height", 2); object oldWidth = EditorContext.ImgElement.getAttribute("width", 2); EditorContext.ImgElement.removeAttribute("width", 0); EditorContext.ImgElement.removeAttribute("height", 0); int width = ((IHTMLImgElement)EditorContext.ImgElement).width; int height = ((IHTMLImgElement)EditorContext.ImgElement).height; if (oldHeight != null) EditorContext.ImgElement.setAttribute("height", oldHeight, 0); if (oldWidth != null) EditorContext.ImgElement.setAttribute("width", oldWidth, 0); imageSizeControl.LoadImageSize(imageSize, new Size(width, height), EditorContext.ImageRotation); } else { imageSizeControl.LoadImageSize(imageSize, EditorContext.SourceImageSize, EditorContext.ImageRotation); } }
public void Decorate(ImageDecoratorContext context) { bool useOriginalImage = true; HtmlImageResizeDecoratorSettings settings = new HtmlImageResizeDecoratorSettings(context.Settings, context.ImgElement); if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert || context.InvocationSource == ImageDecoratorInvocationSource.Reset) { // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. // If ImageSizeName is set, then use that instead of default values if (settings.IsImageSizeNameSet && context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert) { // We must be copying settings from another instance of the same image settings.SetImageSize(settings.ImageSize, settings.ImageSizeName); // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. // Also if we are copying settings, then use the image instance from context instead of the // original image. This ensures we use the cropped image (if any) to resize. useOriginalImage = false; } else { //calculate the default image size and rotation. If the camera has indicated that the //orientation of the photo is rotated (in the EXIF data), shift the rotation appropriately //to insert the image correctly. //Fix the image orientation based on the Exif data (added by digital cameras). RotateFlipType fixedRotation = ImageUtils.GetFixupRotateFlipFromExifOrientation(context.Image); settings.Rotation = fixedRotation; settings.BaseSize = context.Image.Size; //the default size is a scaled version of the image based on the default inline size constraints. Size defaultBoundsSize; if (settings.DefaultBoundsSizeName != ImageSizeName.Full) { defaultBoundsSize = settings.DefaultBoundsSize; } else //original size is default, so we aren't going to scale { defaultBoundsSize = context.Image.Size; } //calulate the base image size to scale from. If the image is rotated 90 degrees, then switch the height/width Size baseImageSize = context.Image.Size; if (ImageUtils.IsRotated90(settings.Rotation)) { baseImageSize = new Size(baseImageSize.Height, baseImageSize.Width); } //calculate and set the scaled default size using the defaultSizeBounds //Note: if the image dimensions are smaller than the default, don't scale that dimension (bug 419446) Size defaultSize = ImageUtils.GetScaledImageSize(Math.Min(baseImageSize.Width, defaultBoundsSize.Width), Math.Min(baseImageSize.Height, defaultBoundsSize.Height), baseImageSize); if (defaultSize.Width < defaultBoundsSize.Width && defaultSize.Height < defaultBoundsSize.Height) { settings.SetImageSize(defaultSize, ImageSizeName.Full); } else { settings.SetImageSize(defaultSize, settings.DefaultBoundsSizeName); } } } else if (settings.BaseSizeChanged(context.Image)) { Size newBaseSize = context.Image.Size; settings.SetImageSize(AdjustImageSizeForNewBaseSize(true, settings, newBaseSize, settings.Rotation, context), null); settings.BaseSize = newBaseSize; } //this decorator only applies to embedded images. if (context.ImageEmbedType == ImageEmbedType.Embedded && !ImageHelper2.IsAnimated(context.Image)) { Bitmap imageToResize = null; // To make image insertion faster, we've already created an initial resized image on a background thread. if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert && useOriginalImage) { try { string imageSrc = context.ImgElement.getAttribute("src", 2) as string; if (!string.IsNullOrEmpty(imageSrc) && (UrlHelper.IsFileUrl(imageSrc) || File.Exists(new Uri(imageSrc).ToString()))) { Uri imageSrcUri = new Uri(imageSrc); imageToResize = (Bitmap)Image.FromFile(imageSrcUri.LocalPath); } } catch (Exception e) { Debug.Write("Failed to load pre-created initial image: " + e); } } if (imageToResize == null) { imageToResize = context.Image; } // Figure the desired image size by taking the size of the img element // and calculate what borderless image size we'd need to start with // to end up at that size. This is different than simply subtracting // the existing border size, since borders can be relative to the // size of the base image. Size desiredImageSize = settings.BorderMargin.ReverseCalculateImageSize(settings.ImageSizeWithBorder); //resize the image and update the image used by the context. if (desiredImageSize != imageToResize.Size || settings.Rotation != RotateFlipType.RotateNoneFlipNone) { context.Image = ResizeImage(imageToResize, desiredImageSize, settings.Rotation); } else { context.Image = imageToResize; } if (settings.ImageSize != context.Image.Size) { settings.SetImageSize(context.Image.Size, settings.ImageSizeName); } } }