Ejemplo n.º 1
0
        public void Decorate(ImageDecoratorContext context)
        {
            if (context.ImageEmbedType == ImageEmbedType.Embedded && context.InvocationSource != ImageDecoratorInvocationSource.TiltPreview)
            {
                TiltDecoratorSettings settings = new TiltDecoratorSettings(context.Settings);
                if (settings.TiltDegrees != 0)
                {
                    DropShadowBorderDecoratorSettings borderSettings =
                        new DropShadowBorderDecoratorSettings(context);

                    Size oldSize = context.Image.Size;
                    Debug.WriteLine(
                        string.Format(CultureInfo.InvariantCulture, "Tilting {0}x{1} image by {2} degrees", context.Image.Width, context.Image.Height,
                                      settings.TiltDegrees));

                    context.Image =
                        ImageHelper.RotateBitmap(context.Image, settings.TiltDegrees, borderSettings.BackgroundColor);
                    Size newSize = context.Image.Size;

                    context.BorderMargin = new ImageBorderMargin(
                        context.BorderMargin,
                        newSize.Width - oldSize.Width,
                        newSize.Height - oldSize.Height,
                        new BorderCalculation(newSize.Width / (float)oldSize.Width, newSize.Height / (float)oldSize.Height));
                }
            }
        }
Ejemplo n.º 2
0
        public void Decorate(ImageDecoratorContext context)
        {
            if (context.ImageEmbedType == ImageEmbedType.Embedded && context.InvocationSource != ImageDecoratorInvocationSource.TiltPreview)
            {
                TiltDecoratorSettings settings = new TiltDecoratorSettings(context.Settings);
                if (settings.TiltDegrees != 0)
                {
                    DropShadowBorderDecoratorSettings borderSettings =
                        new DropShadowBorderDecoratorSettings(context);

                    Size oldSize = context.Image.Size;
                    Debug.WriteLine(
                        string.Format(CultureInfo.InvariantCulture, "Tilting {0}x{1} image by {2} degrees", context.Image.Width, context.Image.Height,
                                      settings.TiltDegrees));

                    context.Image =
                        ImageHelper.RotateBitmap(context.Image, settings.TiltDegrees, borderSettings.BackgroundColor);
                    Size newSize = context.Image.Size;

                    context.BorderMargin = new ImageBorderMargin(
                        context.BorderMargin,
                        newSize.Width - oldSize.Width,
                        newSize.Height - oldSize.Height,
                        new BorderCalculation(newSize.Width / (float)oldSize.Width, newSize.Height / (float)oldSize.Height));
                }
            }
        }
 protected void HideHtmlBorder(ImageDecoratorContext context)
 {
     //remove any image style borders
     context.ImgElement.style.border = "0px;";
     context.ImgElement.setAttribute("border", "0", 0);
     // padding and background image could also interfere with borders
     context.ImgElement.style.padding         = "0px;";
     context.ImgElement.style.backgroundImage = "none";
 }
 protected void HideHtmlBorder(ImageDecoratorContext context)
 {
     //remove any image style borders
     context.ImgElement.style.border = "0px;";
     context.ImgElement.setAttribute("border", "0", 0);
     // padding and background image could also interfere with borders
     context.ImgElement.style.padding = "0px;";
     context.ImgElement.style.backgroundImage = "none";
 }
Ejemplo n.º 5
0
        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 override void Decorate(ImageDecoratorContext context)
        {
            HtmlBorderDecoratorSettings settings = new HtmlBorderDecoratorSettings(context.ImgElement);
            settings.InheritBorder = true;

            if (context.ImageEmbedType == ImageEmbedType.Embedded)
            {
                context.BorderMargin = ImageBorderMargin.Empty;
            }
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            NoBorderDecoratorSettings settings = new NoBorderDecoratorSettings(context.ImgElement);

            settings.NoBorder = true;

            if (context.ImageEmbedType == ImageEmbedType.Embedded)
            {
                context.BorderMargin = ImageBorderMargin.Empty;
            }
        }
Ejemplo n.º 8
0
 public void Decorate(ImageDecoratorContext context)
 {
     if (context.InvocationSource == ImageDecoratorInvocationSource.Reset ||
         context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert)
     {
         //set the default HTML for this decorator.
         HtmlAlignDecoratorSettings settings = new HtmlAlignDecoratorSettings(context.Settings, context.ImgElement, context.InvocationSource);
         settings.Alignment = settings.DefaultAlignment;
     }
     //Note: all other times, this decorator is applied directly by the editor.
 }
 public void Decorate(ImageDecoratorContext context)
 {
     if (context.InvocationSource == ImageDecoratorInvocationSource.Reset ||
         context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert)
     {
         //set the default HTML for this decorator.
         HtmlAlignDecoratorSettings settings = new HtmlAlignDecoratorSettings(context.Settings, context.ImgElement, context.InvocationSource);
         settings.Alignment = settings.DefaultAlignment;
     }
     //Note: all other times, this decorator is applied directly by the editor.
 }
Ejemplo n.º 10
0
        public void Decorate(ImageDecoratorContext context)
        {
            WatermarkDecoratorSettings settings = new WatermarkDecoratorSettings(context.Settings);

            if (string.IsNullOrEmpty(settings.Text))
            {
                return;
            }

            Bitmap bitmap = new Bitmap(context.Image.Width, context.Image.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(context.Image, 0, 0, context.Image.Width, context.Image.Height);

                Font  font  = new Font(settings.FontFamily, settings.FontSize * (96f / 72f), GraphicsUnit.Pixel);
                SizeF sizef = g.MeasureString(settings.Text, font);

                int x = 0;
                int y = 0;
                switch (settings.Position)
                {
                case (WatermarkPosition.TopLeft):
                    break;

                case (WatermarkPosition.TopRight):
                    x = Convert.ToInt32(Math.Max(bitmap.Width - sizef.Width - 2, 0));
                    break;

                case (WatermarkPosition.Centered):
                    x = Convert.ToInt32(Math.Max((bitmap.Width / 2) - (sizef.Width / 2), 0));
                    y = Convert.ToInt32(Math.Max((bitmap.Height / 2) - (sizef.Height / 2), 0));
                    break;

                case (WatermarkPosition.BottomLeft):
                    y = Convert.ToInt32(Math.Max(bitmap.Height - sizef.Height, 0));
                    break;

                case (WatermarkPosition.BottomRight):
                    x = Convert.ToInt32(Math.Max(bitmap.Width - sizef.Width - 2, 0));
                    y = Convert.ToInt32(Math.Max(bitmap.Height - sizef.Height, 0));
                    break;
                }

                g.DrawString(settings.Text, font,
                             new SolidBrush(Color.FromArgb(153, 0, 0, 0)), x, y);

                g.DrawString(settings.Text, font,
                             new SolidBrush(Color.FromArgb(153, 255, 255, 255)), x - 1, y - 1);
            }

            context.Image = bitmap;
        }
        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;
            }
        }
Ejemplo n.º 12
0
 public void Decorate(ImageDecoratorContext context)
 {
     if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert ||
         context.InvocationSource == ImageDecoratorInvocationSource.Reset)
     {
         HtmlMarginDecoratorSettings settings = new HtmlMarginDecoratorSettings(context.Settings, context.ImgElement);
         if (settings.UseUserCustomMargin)
         {
             settings.Margin = settings.UserDefaultMargin;
         }
         else
         {
             settings.Margin = HtmlMarginDecoratorSettings.WriterDefaultMargin;
         }
     }
 }
        public void Decorate(ImageDecoratorContext context)
        {
            if (context.ImageEmbedType == ImageEmbedType.Embedded &&
               (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert ||
                context.InvocationSource == ImageDecoratorInvocationSource.Reset)
                )
            {
                HtmlAltTextDecoratorSettings settings = new HtmlAltTextDecoratorSettings(context.ImgElement);
                Uri uri = context.SourceImageUri;

                //set the default AltText value
                string altText = CalculateAltText(uri);
                settings.AltText = altText;
                settings.Title = altText;
            }
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            const int BORDER_WIDTH = 8;
            const int SHADOW_WIDTH = 4;
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            context.Image = ImageUtils.ApplyDropShadowOutside(context.Image, settings.BackgroundColor, settings.ShadowColor, SHADOW_WIDTH, BORDER_WIDTH);

            //update the margin value to reflect the border added by this decorator.
            int borderWidth = BORDER_WIDTH * 2 + SHADOW_WIDTH;
            int borderHeight = borderWidth;
            context.BorderMargin =
                new ImageBorderMargin(borderWidth, borderHeight, new BorderCalculation(borderWidth, borderHeight));

            HideHtmlBorder(context);
        }
Ejemplo n.º 15
0
        public void Decorate(ImageDecoratorContext context)
        {
            if (context.ImageEmbedType == ImageEmbedType.Embedded &&
                (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert ||
                 context.InvocationSource == ImageDecoratorInvocationSource.Reset)
                )
            {
                HtmlAltTextDecoratorSettings settings = new HtmlAltTextDecoratorSettings(context.ImgElement);
                Uri uri = context.SourceImageUri;

                //set the default AltText value
                string altText = CalculateAltText(uri);
                settings.AltText = altText;
                settings.Title   = altText;
            }
        }
 public void Decorate(ImageDecoratorContext context)
 {
     if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert ||
         context.InvocationSource == ImageDecoratorInvocationSource.Reset)
     {
         HtmlMarginDecoratorSettings settings = new HtmlMarginDecoratorSettings(context.Settings, context.ImgElement);
         if (settings.UseUserCustomMargin)
         {
             settings.Margin = settings.UserDefaultMargin;
         }
         else
         {
             settings.Margin = HtmlMarginDecoratorSettings.WriterDefaultMargin;
         }
     }
 }
Ejemplo n.º 17
0
        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;
            }
        }
Ejemplo n.º 18
0
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Rectangle adjustment = AdjustImagePositionAndSize(context);
            Bitmap    bitmap     = new Bitmap(
                context.Image.Width + adjustment.Width,
                context.Image.Height + adjustment.Height,
                PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (Brush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, bitmap.Width, bitmap.Height);

                int[]       sliceLines = SliceLines;
                BorderPaint bp         = new BorderPaint(BorderImage, false, BorderPaintMode.Default, sliceLines[0], sliceLines[1], sliceLines[2], sliceLines[3]);
                if (DiscardColors)
                {
                    using (ImageAttributes ia = new ImageAttributes())
                    {
                        ia.SetColorMatrix(ImageHelper.GetColorOverrideImageMatrix(settings.ShadowColor));
                        bp.ImageAttributes = ia;
                        bp.DrawBorder(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
                    }
                }
                else
                {
                    bp.DrawBorder(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
                }

                g.DrawImage(context.Image,
                            adjustment.Left,
                            adjustment.Top,
                            context.Image.Width,
                            context.Image.Height);

                OnBorderDecorationComplete(g, context);
            }

            context.Image        = bitmap;
            context.BorderMargin =
                new ImageBorderMargin(adjustment.Width, adjustment.Height,
                                      new BorderCalculation(adjustment.Width, adjustment.Height));
            HideHtmlBorder(context);
        }
Ejemplo n.º 19
0
        public override void Decorate(ImageDecoratorContext context)
        {
            const int BORDER_WIDTH = 8;
            const int SHADOW_WIDTH = 4;
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            context.Image = ImageUtils.ApplyDropShadowOutside(context.Image, settings.BackgroundColor, settings.ShadowColor, SHADOW_WIDTH, BORDER_WIDTH);

            //update the margin value to reflect the border added by this decorator.
            int borderWidth  = BORDER_WIDTH * 2 + SHADOW_WIDTH;
            int borderHeight = borderWidth;

            context.BorderMargin =
                new ImageBorderMargin(borderWidth, borderHeight, new BorderCalculation(borderWidth, borderHeight));

            HideHtmlBorder(context);
        }
        public void Decorate(ImageDecoratorContext context)
        {
            WatermarkDecoratorSettings settings = new WatermarkDecoratorSettings(context.Settings);
            if (string.IsNullOrEmpty(settings.Text))
                return;

            Bitmap bitmap = new Bitmap(context.Image.Width, context.Image.Height);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(context.Image, 0, 0, context.Image.Width, context.Image.Height);

                Font font = new Font(settings.FontFamily, settings.FontSize * (96f / 72f), GraphicsUnit.Pixel);
                SizeF sizef = g.MeasureString(settings.Text, font);

                int x = 0;
                int y = 0;
                switch (settings.Position)
                {
                    case (WatermarkPosition.TopLeft):
                        break;
                    case (WatermarkPosition.TopRight):
                        x = Convert.ToInt32(Math.Max(bitmap.Width - sizef.Width - 2, 0));
                        break;
                    case (WatermarkPosition.Centered):
                        x = Convert.ToInt32(Math.Max((bitmap.Width / 2) - (sizef.Width / 2), 0));
                        y = Convert.ToInt32(Math.Max((bitmap.Height / 2) - (sizef.Height / 2), 0));
                        break;
                    case (WatermarkPosition.BottomLeft):
                        y = Convert.ToInt32(Math.Max(bitmap.Height - sizef.Height, 0));
                        break;
                    case (WatermarkPosition.BottomRight):
                        x = Convert.ToInt32(Math.Max(bitmap.Width - sizef.Width - 2, 0));
                        y = Convert.ToInt32(Math.Max(bitmap.Height - sizef.Height, 0));
                        break;
                }

                g.DrawString(settings.Text, font,
                    new SolidBrush(Color.FromArgb(153, 0, 0, 0)), x, y);

                g.DrawString(settings.Text, font,
                    new SolidBrush(Color.FromArgb(153, 255, 255, 255)), x - 1, y - 1);
            }

            context.Image = bitmap;
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Rectangle adjustment = AdjustImagePositionAndSize(context);
            Bitmap bitmap = new Bitmap(
                context.Image.Width + adjustment.Width,
                context.Image.Height + adjustment.Height,
                PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (Brush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, bitmap.Width, bitmap.Height);

                int[] sliceLines = SliceLines;
                BorderPaint bp = new BorderPaint(BorderImage, false, BorderPaintMode.Default, sliceLines[0], sliceLines[1], sliceLines[2], sliceLines[3]);
                if (DiscardColors)
                {
                    using (ImageAttributes ia = new ImageAttributes())
                    {
                        ia.SetColorMatrix(ImageHelper.GetColorOverrideImageMatrix(settings.ShadowColor));
                        bp.ImageAttributes = ia;
                        bp.DrawBorder(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
                    }
                }
                else
                    bp.DrawBorder(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height));

                g.DrawImage(context.Image,
                            adjustment.Left,
                            adjustment.Top,
                            context.Image.Width,
                            context.Image.Height);

                OnBorderDecorationComplete(g, context);
            }

            context.Image = bitmap;
            context.BorderMargin =
                new ImageBorderMargin(adjustment.Width, adjustment.Height,
                                            new BorderCalculation(adjustment.Width, adjustment.Height));
            HideHtmlBorder(context);
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Bitmap bitmap = new Bitmap(context.Image.Width, context.Image.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(context.Image, 0, 0, context.Image.Width, context.Image.Height);

                using (ImageAttributes ia = new ImageAttributes())
                {
                    // The color matrix causes all color information to
                    // be replaced by the background color, while preserving
                    // the alpha of the source image.
                    ia.SetColorMatrix(ImageHelper.GetColorOverrideImageMatrix(settings.BackgroundColor));

                    Bitmap corner =
                        ResourceHelper.LoadAssemblyResourceBitmap("PostHtmlEditing.ImageEditing.Images.Corner16.png");

                    g.DrawImage(corner,
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                0, 0, corner.Width, corner.Height,
                                GraphicsUnit.Pixel, ia);
                    g.DrawImage(corner,
                                MakePoints(bitmap.Width, 0, bitmap.Width, corner.Width, bitmap.Width - corner.Height, 0),
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                GraphicsUnit.Pixel, ia);
                    g.DrawImage(corner,
                                MakePoints(bitmap.Width, bitmap.Height, bitmap.Width - corner.Width, bitmap.Height, bitmap.Width, bitmap.Height - corner.Height),
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                GraphicsUnit.Pixel, ia);
                    g.DrawImage(corner,
                                MakePoints(0, bitmap.Height, 0, bitmap.Height - corner.Width, corner.Width, bitmap.Height),
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                GraphicsUnit.Pixel, ia);
                }
            }
            context.Image        = bitmap;
            context.BorderMargin = ImageBorderMargin.Empty;
            HideHtmlBorder(context);
        }
Ejemplo n.º 23
0
        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;
            }
        }
Ejemplo n.º 24
0
        public override void Decorate(ImageDecoratorContext context)
        {
            Bitmap polaroidBorder = ResourceHelper.LoadAssemblyResourceBitmap("PostHtmlEditing.ImageEditing.Images.PolaroidBorder2.png");

            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Size originalSize = context.Image.Size;

            float scaleX    = originalSize.Width / (float)PORTAL_RECT.Width;
            float scaleY    = originalSize.Height / (float)PORTAL_RECT.Height;
            Size  finalSize = new Size((int)(polaroidBorder.Width * scaleX), (int)(polaroidBorder.Height * scaleY));

            Bitmap output = new Bitmap(finalSize.Width, finalSize.Height);

            using (Graphics g = Graphics.FromImage(output))
            {
                using (SolidBrush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, output.Width, output.Height);

                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                RectangleF realPortal = new RectangleF(
                    PORTAL_RECT.X * scaleX,
                    PORTAL_RECT.Y * scaleY,
                    PORTAL_RECT.Width * scaleX,
                    PORTAL_RECT.Height * scaleY);

                realPortal.Inflate(1, 1);
                g.DrawImage(context.Image, realPortal, new RectangleF(0, 0, originalSize.Width, originalSize.Height), GraphicsUnit.Pixel);
                g.DrawImage(polaroidBorder, 0, 0, output.Width, output.Height);
            }

            context.Image        = output;
            context.BorderMargin = new ImageBorderMargin(
                output.Width - originalSize.Width, output.Height - originalSize.Height,
                new BorderCalculation(output.Width / (float)originalSize.Width, output.Height / (float)originalSize.Height));

            HideHtmlBorder(context);
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Bitmap bitmap = new Bitmap(context.Image.Width, context.Image.Height);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(context.Image, 0, 0, context.Image.Width, context.Image.Height);

                using (ImageAttributes ia = new ImageAttributes())
                {
                    // The color matrix causes all color information to
                    // be replaced by the background color, while preserving
                    // the alpha of the source image.
                    ia.SetColorMatrix(ImageHelper.GetColorOverrideImageMatrix(settings.BackgroundColor));

                    Bitmap corner =
                        ResourceHelper.LoadAssemblyResourceBitmap("PostHtmlEditing.ImageEditing.Images.Corner16.png");

                    g.DrawImage(corner,
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                0, 0, corner.Width, corner.Height,
                                GraphicsUnit.Pixel, ia);
                    g.DrawImage(corner,
                                MakePoints(bitmap.Width, 0, bitmap.Width, corner.Width, bitmap.Width - corner.Height, 0),
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                GraphicsUnit.Pixel, ia);
                    g.DrawImage(corner,
                                MakePoints(bitmap.Width, bitmap.Height, bitmap.Width - corner.Width, bitmap.Height, bitmap.Width, bitmap.Height - corner.Height),
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                GraphicsUnit.Pixel, ia);
                    g.DrawImage(corner,
                                MakePoints(0, bitmap.Height, 0, bitmap.Height - corner.Width, corner.Width, bitmap.Height),
                                new Rectangle(0, 0, corner.Width, corner.Height),
                                GraphicsUnit.Pixel, ia);
                }
            }
            context.Image = bitmap;
            context.BorderMargin = ImageBorderMargin.Empty;
            HideHtmlBorder(context);
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            Bitmap polaroidBorder = ResourceHelper.LoadAssemblyResourceBitmap("PostHtmlEditing.ImageEditing.Images.PolaroidBorder2.png");

            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Size originalSize = context.Image.Size;

            float scaleX = originalSize.Width / (float)PORTAL_RECT.Width;
            float scaleY = originalSize.Height / (float)PORTAL_RECT.Height;
            Size finalSize = new Size((int)(polaroidBorder.Width * scaleX), (int)(polaroidBorder.Height * scaleY));

            Bitmap output = new Bitmap(finalSize.Width, finalSize.Height);
            using (Graphics g = Graphics.FromImage(output))
            {
                using (SolidBrush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, output.Width, output.Height);

                g.CompositingMode = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                RectangleF realPortal = new RectangleF(
                    PORTAL_RECT.X * scaleX,
                    PORTAL_RECT.Y * scaleY,
                    PORTAL_RECT.Width * scaleX,
                    PORTAL_RECT.Height * scaleY);

                realPortal.Inflate(1, 1);
                g.DrawImage(context.Image, realPortal, new RectangleF(0, 0, originalSize.Width, originalSize.Height), GraphicsUnit.Pixel);
                g.DrawImage(polaroidBorder, 0, 0, output.Width, output.Height);
            }

            context.Image = output;
            context.BorderMargin = new ImageBorderMargin(
                output.Width - originalSize.Width, output.Height - originalSize.Height,
                new BorderCalculation(output.Width / (float)originalSize.Width, output.Height / (float)originalSize.Height));

            HideHtmlBorder(context);
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Bitmap bitmap = new Bitmap(context.Image.Width + borderWidth * 2, context.Image.Height + borderWidth * 2);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (Brush b = new SolidBrush(settings.ShadowColor))
                {
                    g.FillRectangle(b, 0, 0, bitmap.Width, borderWidth);
                    g.FillRectangle(b, 0, borderWidth, borderWidth, bitmap.Height);
                    g.FillRectangle(b, borderWidth, bitmap.Height - borderWidth, bitmap.Width - borderWidth, borderWidth);
                    g.FillRectangle(b, bitmap.Width - borderWidth, borderWidth, borderWidth, bitmap.Height - borderWidth * 2);
                }
                g.DrawImage(context.Image, borderWidth, borderWidth, context.Image.Width, context.Image.Height);
            }
            context.Image = bitmap;
            context.BorderMargin =
                new ImageBorderMargin(borderWidth * 2, borderWidth * 2, new BorderCalculation(borderWidth * 2, borderWidth * 2));

            HideHtmlBorder(context);
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Bitmap bitmap = new Bitmap(context.Image.Width + borderWidth * 2, context.Image.Height + borderWidth * 2);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (Brush b = new SolidBrush(settings.ShadowColor))
                {
                    g.FillRectangle(b, 0, 0, bitmap.Width, borderWidth);
                    g.FillRectangle(b, 0, borderWidth, borderWidth, bitmap.Height);
                    g.FillRectangle(b, borderWidth, bitmap.Height - borderWidth, bitmap.Width - borderWidth, borderWidth);
                    g.FillRectangle(b, bitmap.Width - borderWidth, borderWidth, borderWidth, bitmap.Height - borderWidth * 2);
                }
                g.DrawImage(context.Image, borderWidth, borderWidth, context.Image.Width, context.Image.Height);
            }
            context.Image        = bitmap;
            context.BorderMargin =
                new ImageBorderMargin(borderWidth * 2, borderWidth * 2, new BorderCalculation(borderWidth * 2, borderWidth * 2));

            HideHtmlBorder(context);
        }
Ejemplo n.º 29
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Warm(context.Image, _temperature);
 }
 public abstract void Decorate(ImageDecoratorContext context);
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Saturate(context.Image);
 }
Ejemplo n.º 32
0
 protected override Rectangle AdjustImagePositionAndSize(ImageDecoratorContext context)
 {
     return(new Rectangle(22, 14, 102 - 58, 98 - 54));
 }
Ejemplo n.º 33
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Sharpen(context.Image);
 }
 public void Decorate(ImageDecoratorContext context)
 {
 }
Ejemplo n.º 35
0
        internal static Size AdjustImageSizeForNewBaseSize(bool allowEnlargement, IResizeDecoratorSettings s, Size newBaseSize, RotateFlipType rotation, ImageDecoratorContext context)
        {
            Size rotatedBaseSize = ImageUtils.IsRotated90(rotation)
                ? new Size(newBaseSize.Height, newBaseSize.Width)
                : newBaseSize;

            if (s.ImageSizeName != ImageSizeName.Custom)
            {
                // If a standard image size is being used, fit to that

                Size sizeBounds = ImageSizeHelper.GetSizeConstraints(s.ImageSizeName);
                if (!allowEnlargement)
                {
                    sizeBounds.Width  = Math.Min(rotatedBaseSize.Width, sizeBounds.Width);
                    sizeBounds.Height = Math.Min(rotatedBaseSize.Height, sizeBounds.Height);
                }
                return(ImageUtils.GetScaledImageSize(sizeBounds.Width, sizeBounds.Height, rotatedBaseSize));
            }
            else
            {
                // If custom size, but we know the base size, preserve
                // the aspect ratio "skew" (difference in x and y DPI)
                // and pixel area

                Size imageSize = s.ImageSize;
                // Need to get the image size to the non-rotated angle,
                // because s.BaseSize dimensions are always pre-rotation.
                // Although ImageSize has not been fully updated for this
                // decorator yet (that's what we're trying to do here),
                // the width/height gets flipped immediately when a
                // rotation is applied, so rotation is already taken
                // into account.
                if (ImageUtils.IsRotated90(rotation))
                {
                    imageSize = new Size(imageSize.Height, imageSize.Width);
                }

                // If the base size has not been set yet, we have to guess.
                // This basically means the image was inserted using an older
                // build of Writer that did not have the crop feature. Ideally
                // we would use the original image size, but this is expensive
                // to get from here. It just so happens that newBaseSize works
                // for now because the crop dialog defaults to the same aspect
                // ratio as the original image, but if that ever changes this
                // will break.
#if DEBUG
                if (s.BaseSize == null)
                {
                    using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(context.SourceImageUri.LocalPath))
                    {
                        Size size = new Size(Math.Max(1, bitmap.Width / 2),
                                             Math.Max(1, bitmap.Height / 2));
                        Debug.Assert(size.Equals(newBaseSize) || bitmap.Size.Equals(newBaseSize), "Check base size assumptions. Can't use 's.BaseSize ?? newBaseSize', instead must calculate original image size (context.SourceImageUri.LocalPath).");
                    }
                }
#endif
                Size baseSize = s.BaseSize ?? newBaseSize;

                double xFactor = imageSize.Width / (double)baseSize.Width;
                double yFactor = imageSize.Height / (double)baseSize.Height;
                newBaseSize = new Size(
                    (int)Math.Round(xFactor * newBaseSize.Width),
                    (int)Math.Round(yFactor * newBaseSize.Height)
                    );

                // Need to re-apply the rotation if necessary.
                if (ImageUtils.IsRotated90(rotation))
                {
                    newBaseSize = new Size(newBaseSize.Height, newBaseSize.Width);
                }

                // At this point, newBaseSize has the right aspect ratio; we now
                // need to scale it so it uses about the same number of pixels
                // as it did before.

                double factor = (imageSize.Width * imageSize.Height) / (double)(newBaseSize.Width * newBaseSize.Height);
                factor             = Math.Sqrt(factor);
                newBaseSize.Width  = (int)Math.Round(newBaseSize.Width * factor);
                newBaseSize.Height = (int)Math.Round(newBaseSize.Height * factor);

                if (!allowEnlargement)
                {
                    if (newBaseSize.Width > rotatedBaseSize.Width || newBaseSize.Height > rotatedBaseSize.Height)
                    {
                        newBaseSize = ImageUtils.GetScaledImageSize(rotatedBaseSize.Width, rotatedBaseSize.Height, newBaseSize);
                    }
                }

                return(newBaseSize);
            }
        }
Ejemplo n.º 36
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Warm(context.Image, _temperature);
 }
Ejemplo n.º 37
0
        public void Decorate(ImageDecoratorContext context)
        {
            BrightnessDecoratorSettings bsettings = new BrightnessDecoratorSettings(context.Settings);

            context.Image = AdjustBrightness(bsettings.Brightness, bsettings.Contrast, context.Image);
        }
        internal static Size AdjustImageSizeForNewBaseSize(bool allowEnlargement, IResizeDecoratorSettings s, Size newBaseSize, RotateFlipType rotation, ImageDecoratorContext context)
        {
            Size rotatedBaseSize = ImageUtils.IsRotated90(rotation)
                ? new Size(newBaseSize.Height, newBaseSize.Width)
                : newBaseSize;

            if (s.ImageSizeName != ImageSizeName.Custom)
            {
                // If a standard image size is being used, fit to that

                Size sizeBounds = ImageSizeHelper.GetSizeConstraints(s.ImageSizeName);
                if (!allowEnlargement)
                {
                    sizeBounds.Width = Math.Min(rotatedBaseSize.Width, sizeBounds.Width);
                    sizeBounds.Height = Math.Min(rotatedBaseSize.Height, sizeBounds.Height);
                }
                return ImageUtils.GetScaledImageSize(sizeBounds.Width, sizeBounds.Height, rotatedBaseSize);
            }
            else
            {
                // If custom size, but we know the base size, preserve
                // the aspect ratio "skew" (difference in x and y DPI)
                // and pixel area

                Size imageSize = s.ImageSize;
                // Need to get the image size to the non-rotated angle,
                // because s.BaseSize dimensions are always pre-rotation.
                // Although ImageSize has not been fully updated for this
                // decorator yet (that's what we're trying to do here),
                // the width/height gets flipped immediately when a
                // rotation is applied, so rotation is already taken
                // into account.
                if (ImageUtils.IsRotated90(rotation))
                    imageSize = new Size(imageSize.Height, imageSize.Width);

                // If the base size has not been set yet, we have to guess.
                // This basically means the image was inserted using an older
                // build of Writer that did not have the crop feature. Ideally
                // we would use the original image size, but this is expensive
                // to get from here. It just so happens that newBaseSize works
                // for now because the crop dialog defaults to the same aspect
                // ratio as the original image, but if that ever changes this
                // will break.
#if DEBUG
                if (s.BaseSize == null)
                {
                    using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(context.SourceImageUri.LocalPath))
                    {
                        Size size = new Size(Math.Max(1, bitmap.Width / 2),
                                             Math.Max(1, bitmap.Height / 2));
                        Debug.Assert(size.Equals(newBaseSize) || bitmap.Size.Equals(newBaseSize), "Check base size assumptions. Can't use 's.BaseSize ?? newBaseSize', instead must calculate original image size (context.SourceImageUri.LocalPath).");
                    }
                }
#endif
                Size baseSize = s.BaseSize ?? newBaseSize;

                double xFactor = imageSize.Width / (double)baseSize.Width;
                double yFactor = imageSize.Height / (double)baseSize.Height;
                newBaseSize = new Size(
                    (int)Math.Round(xFactor * newBaseSize.Width),
                    (int)Math.Round(yFactor * newBaseSize.Height)
                    );

                // Need to re-apply the rotation if necessary.
                if (ImageUtils.IsRotated90(rotation))
                    newBaseSize = new Size(newBaseSize.Height, newBaseSize.Width);

                // At this point, newBaseSize has the right aspect ratio; we now
                // need to scale it so it uses about the same number of pixels
                // as it did before.

                double factor = (imageSize.Width * imageSize.Height) / (double)(newBaseSize.Width * newBaseSize.Height);
                factor = Math.Sqrt(factor);
                newBaseSize.Width = (int)Math.Round(newBaseSize.Width * factor);
                newBaseSize.Height = (int)Math.Round(newBaseSize.Height * factor);

                if (!allowEnlargement)
                {
                    if (newBaseSize.Width > rotatedBaseSize.Width || newBaseSize.Height > rotatedBaseSize.Height)
                        newBaseSize = ImageUtils.GetScaledImageSize(rotatedBaseSize.Width, rotatedBaseSize.Height, newBaseSize);
                }

                return newBaseSize;
            }
        }
Ejemplo n.º 39
0
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Bitmap original = context.Image;

            int reflectionHeight = original.Height / 3;

            Bitmap bitmap = new Bitmap(original.Width, original.Height + reflectionHeight);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
#if !TRUE_TRANSPARENCY
                using (Brush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, bitmap.Width, bitmap.Height);
#endif

                g.DrawImage(original, 0, 0, original.Width, original.Height);

                Rectangle reflectionRect = new Rectangle(0, original.Height, bitmap.Width, reflectionHeight);
                Rectangle clipRect       = new Rectangle(reflectionRect.X, reflectionRect.Y + 1, reflectionRect.Width, reflectionRect.Height - 1);
                g.SetClip(clipRect);

                using (new QuickTimer("Draw faded reflection"))
                {
#if TRUE_TRANSPARENCY
                    float startOpacity = 0.5f;
                    float endOpacity   = 0f;

                    for (int vOffset = 0; ; vOffset++)
                    {
                        int destRow = reflectionRect.Top + 1 + vOffset;
                        if (destRow >= bitmap.Height)
                        {
                            break;
                        }
                        int   srcRow  = original.Height - vOffset - 1;
                        float opacity =
                            Math.Min(1.0f,
                                     startOpacity +
                                     ((endOpacity - startOpacity) * (vOffset / (float)reflectionRect.Height)));

                        ImageAttributes ia = new ImageAttributes();
                        ColorMatrix     cm = new ColorMatrix();
                        cm.Matrix33 = opacity;
                        ia.SetColorMatrix(cm);
                        g.DrawImage(original,
                                    new Rectangle(0, destRow, reflectionRect.Width, 1),
                                    0, srcRow, reflectionRect.Width, 1,
                                    GraphicsUnit.Pixel,
                                    ia);
                    }
#else
                    Point upperLeft  = new Point(0, original.Height * 2);
                    Point upperRight = new Point(original.Width, original.Height * 2);
                    Point lowerLeft  = new Point(0, original.Height);
                    g.DrawImage(original, new Point[] { upperLeft, upperRight, lowerLeft });
                    using (
                        Brush b =
                            new LinearGradientBrush(reflectionRect, Color.FromArgb(128, settings.BackgroundColor),
                                                    settings.BackgroundColor, LinearGradientMode.Vertical))
                        g.FillRectangle(b, reflectionRect);
#endif
                }
            }

            context.Image = bitmap;
            //update the margin value to reflect the border added by this decorator.
            context.BorderMargin = new ImageBorderMargin(0, reflectionHeight, new BorderCalculation(1f, 1 + (1 / 3f)));

            HideHtmlBorder(context);
        }
Ejemplo n.º 40
0
 public DropShadowBorderDecoratorSettings(ImageDecoratorContext context)
 {
     Element       = context.ImgElement;
     editorOptions = context.EditorOptions;
 }
Ejemplo n.º 41
0
 public void Decorate(ImageDecoratorContext context)
 {
     //convert the image to black and white
     context.Image = ConvertToBlackAndWhite(context.Image);
 }
 protected override Rectangle AdjustImagePositionAndSize(ImageDecoratorContext context)
 {
     return new Rectangle(22, 14, 102 - 58, 98 - 54);
 }
 public void Decorate(ImageDecoratorContext context)
 {
     BrightnessDecoratorSettings bsettings = new BrightnessDecoratorSettings(context.Settings);
     context.Image = AdjustBrightness(bsettings.Brightness, bsettings.Contrast, context.Image);
 }
 /// <summary>
 /// The size of this rectangle will be added to the size of the
 /// original image to determine the size of the new image.
 ///
 /// The position of this rectangle will be the position in the new
 /// image where the old image will be drawn.
 /// </summary>
 protected abstract Rectangle AdjustImagePositionAndSize(ImageDecoratorContext context);
Ejemplo n.º 45
0
        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);
                }
            }
        }
Ejemplo n.º 46
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Saturate(context.Image);
 }
 protected virtual void OnBorderDecorationComplete(Graphics g, ImageDecoratorContext context)
 {
 }
Ejemplo n.º 48
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Sharpen(context.Image);
 }
Ejemplo n.º 49
0
 public void Decorate(ImageDecoratorContext context)
 {
     //convert the image to sepia
     context.Image = ConvertToSepia(context.Image);
 }
        public override void Decorate(ImageDecoratorContext context)
        {
            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Bitmap original = context.Image;

            int reflectionHeight = original.Height / 3;

            Bitmap bitmap = new Bitmap(original.Width, original.Height + reflectionHeight);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
#if !TRUE_TRANSPARENCY
                using (Brush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, bitmap.Width, bitmap.Height);
#endif

                g.DrawImage(original, 0, 0, original.Width, original.Height);

                Rectangle reflectionRect = new Rectangle(0, original.Height, bitmap.Width, reflectionHeight);
                Rectangle clipRect = new Rectangle(reflectionRect.X, reflectionRect.Y + 1, reflectionRect.Width, reflectionRect.Height - 1);
                g.SetClip(clipRect);

                using (new QuickTimer("Draw faded reflection"))
                {
#if TRUE_TRANSPARENCY
                    float startOpacity = 0.5f;
                    float endOpacity = 0f;

                    for (int vOffset = 0; ; vOffset++)
                    {
                        int destRow = reflectionRect.Top + 1 + vOffset;
                        if (destRow >= bitmap.Height)
                            break;
                        int srcRow = original.Height - vOffset - 1;
                        float opacity =
                            Math.Min(1.0f,
                                     startOpacity +
                                     ((endOpacity - startOpacity) * (vOffset / (float)reflectionRect.Height)));

                        ImageAttributes ia = new ImageAttributes();
                        ColorMatrix cm = new ColorMatrix();
                        cm.Matrix33 = opacity;
                        ia.SetColorMatrix(cm);
                        g.DrawImage(original,
                                    new Rectangle(0, destRow, reflectionRect.Width, 1),
                                    0, srcRow, reflectionRect.Width, 1,
                                    GraphicsUnit.Pixel,
                                    ia);
                    }
#else
                    Point upperLeft = new Point(0, original.Height * 2);
                    Point upperRight = new Point(original.Width, original.Height * 2);
                    Point lowerLeft = new Point(0, original.Height);
                    g.DrawImage(original, new Point[] { upperLeft, upperRight, lowerLeft });
                    using (
                        Brush b =
                            new LinearGradientBrush(reflectionRect, Color.FromArgb(128, settings.BackgroundColor),
                                                    settings.BackgroundColor, LinearGradientMode.Vertical))
                        g.FillRectangle(b, reflectionRect);
#endif
                }
            }

            context.Image = bitmap;
            //update the margin value to reflect the border added by this decorator.
            context.BorderMargin = new ImageBorderMargin(0, reflectionHeight, new BorderCalculation(1f, 1 + (1 / 3f)));

            HideHtmlBorder(context);
        }
Ejemplo n.º 51
0
 public void Decorate(ImageDecoratorContext context)
 {
     RawImageDecorator.Decorate(context);
 }
 public abstract void Decorate(ImageDecoratorContext context);
 public void Decorate(ImageDecoratorContext context)
 {
     //convert the image to black and white
     context.Image = ConvertToBlackAndWhite(context.Image);
 }
 public DropShadowBorderDecoratorSettings(ImageDecoratorContext context)
 {
     Element = context.ImgElement;
     editorOptions = context.EditorOptions;
 }
 public void Decorate(ImageDecoratorContext context)
 {
 }
Ejemplo n.º 56
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Emboss(context.Image);
 }
Ejemplo n.º 57
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Blur(context.Image);
 }
Ejemplo n.º 58
0
 public void Decorate(ImageDecoratorContext context)
 {
     context.Image = Emboss(context.Image);
 }
        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);
            }
        }
 public void Decorate(ImageDecoratorContext context)
 {
     RawImageDecorator.Decorate(context);
 }