public void Decorate(ImageDecoratorContext context) { HtmlImageTargetDecoratorSettings settings = new HtmlImageTargetDecoratorSettings(context.Settings, context.ImgElement); if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert || context.InvocationSource == ImageDecoratorInvocationSource.Reset) { //set the default link target type. //settings.LinkTarget = settings.DefaultLinkTarget; //the default size is a scaled version of the image based on the default inline size constraints. Size defaultSizeBounds = settings.DefaultTargetBoundsSize; settings.BaseSize = context.Image.Size; //calculate 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(context.ImageRotation)) { 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, defaultSizeBounds.Width), Math.Min(baseImageSize.Height, defaultSizeBounds.Height), baseImageSize); settings.ImageSize = defaultSize; settings.ImageSizeName = settings.DefaultTargetBoundsSizeName; } else if (settings.BaseSizeChanged(context.Image) && context.ImageEmbedType == ImageEmbedType.Linked) { Size newBaseSize = context.Image.Size; settings.ImageSize = HtmlImageResizeDecorator.AdjustImageSizeForNewBaseSize(false, settings, newBaseSize, context.ImageRotation, context); settings.BaseSize = newBaseSize; } if (context.InvocationSource == ImageDecoratorInvocationSource.Reset) { //set the initial link options settings.LinkOptions = settings.DefaultLinkOptions; } //this decorator only applies to linked images. if (context.ImageEmbedType == ImageEmbedType.Linked) { Size imageSize = settings.ImageSize; //resize the image and update the image used by the context. Bitmap bitmap = HtmlImageResizeDecorator.ResizeImage(context.Image, imageSize, context.ImageRotation); context.Image = bitmap; if (settings.ImageSize != bitmap.Size) { settings.ImageSize = bitmap.Size; } } }
public void Decorate(ImageDecoratorContext context) { HtmlImageTargetDecoratorSettings settings = new HtmlImageTargetDecoratorSettings(context.Settings, context.ImgElement); if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert || context.InvocationSource == ImageDecoratorInvocationSource.Reset) { //set the default link target type. //settings.LinkTarget = settings.DefaultLinkTarget; //the default size is a scaled version of the image based on the default inline size constraints. Size defaultSizeBounds = settings.DefaultTargetBoundsSize; settings.BaseSize = context.Image.Size; //calculate 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(context.ImageRotation)) 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, defaultSizeBounds.Width), Math.Min(baseImageSize.Height, defaultSizeBounds.Height), baseImageSize); settings.ImageSize = defaultSize; settings.ImageSizeName = settings.DefaultTargetBoundsSizeName; } else if (settings.BaseSizeChanged(context.Image) && context.ImageEmbedType == ImageEmbedType.Linked) { Size newBaseSize = context.Image.Size; settings.ImageSize = HtmlImageResizeDecorator.AdjustImageSizeForNewBaseSize(false, settings, newBaseSize, context.ImageRotation, context); settings.BaseSize = newBaseSize; } if (context.InvocationSource == ImageDecoratorInvocationSource.Reset) { //set the initial link options settings.LinkOptions = settings.DefaultLinkOptions; } //this decorator only applies to linked images. if (context.ImageEmbedType == ImageEmbedType.Linked) { Size imageSize = settings.ImageSize; //resize the image and update the image used by the context. Bitmap bitmap = HtmlImageResizeDecorator.ResizeImage(context.Image, imageSize, context.ImageRotation); context.Image = bitmap; if (settings.ImageSize != bitmap.Size) settings.ImageSize = bitmap.Size; } }