Example #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));
                }
            }
        }
        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));
                }
            }
        }
        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);
        }
Example #4
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);
        }
Example #5
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);
        }
        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);
        }
        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);
        }
Example #9
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)
        {
            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);
        }
        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);
        }
Example #14
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);
        }