Exemple #1
0
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            int       blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
            Rectangle applyRect  = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                return;
            }
            GraphicsState state = graphics.Save();

            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            if (GDIplus.IsBlurPossible(blurRadius))
            {
                GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false);
            }
            else
            {
                using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect))
                {
                    ImageHelper.ApplyBoxBlur(fastBitmap, blurRadius);
                    fastBitmap.DrawTo(graphics, applyRect);
                }
            }
            graphics.Restore(state);
        }
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            int       pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE);
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (pixelSize <= 1 || rect.Width == 0 || rect.Height == 0)
            {
                // Nothing to do
                return;
            }
            if (rect.Width < pixelSize)
            {
                pixelSize = rect.Width;
            }
            if (rect.Height < pixelSize)
            {
                pixelSize = rect.Height;
            }
            using (IFastBitmap dest = FastBitmap.CreateCloneOf(applyBitmap, rect)) {
                using (IFastBitmap src = FastBitmap.Create(applyBitmap, rect)) {
                    List <Color> colors        = new List <Color>();
                    int          halbPixelSize = pixelSize / 2;
                    for (int y = src.Top - halbPixelSize; y < src.Bottom + halbPixelSize; y = y + pixelSize)
                    {
                        for (int x = src.Left - halbPixelSize; x <= src.Right + halbPixelSize; x = x + pixelSize)
                        {
                            colors.Clear();
                            for (int yy = y; yy < y + pixelSize; yy++)
                            {
                                if (yy >= src.Top && yy < src.Bottom)
                                {
                                    for (int xx = x; xx < x + pixelSize; xx++)
                                    {
                                        if (xx >= src.Left && xx < src.Right)
                                        {
                                            colors.Add(src.GetColorAt(xx, yy));
                                        }
                                    }
                                }
                            }
                            Color currentAvgColor = Colors.Mix(colors);
                            for (int yy = y; yy <= y + pixelSize; yy++)
                            {
                                if (yy >= src.Top && yy < src.Bottom)
                                {
                                    for (int xx = x; xx <= x + pixelSize; xx++)
                                    {
                                        if (xx >= src.Left && xx < src.Right)
                                        {
                                            dest.SetColorAt(xx, yy, currentAvgColor);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                dest.DrawTo(graphics, rect.Location);
            }
        }
Exemple #3
0
        /// <summary>
        /// Implements the Apply code for the Brightness Filet
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="applyBitmap"></param>
        /// <param name="rect"></param>
        /// <param name="renderMode"></param>
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();

            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) {
                Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
                for (int y = fastBitmap.Top; y < fastBitmap.Bottom; y++)
                {
                    for (int x = fastBitmap.Left; x < fastBitmap.Right; x++)
                    {
                        Color color = fastBitmap.GetColorAt(x, y);
                        color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B));
                        fastBitmap.SetColorAt(x, y, color);
                    }
                }
                fastBitmap.DrawTo(graphics, applyRect.Location);
            }
            graphics.Restore(state);
        }
Exemple #4
0
        public Image Pixelate(Image sourceImage, int pixelSize)
        {
            if (sourceImage == null || !(sourceImage is Bitmap))
            {
                return(sourceImage);
            }

            if (sourceImage.Width < pixelSize)
            {
                pixelSize = sourceImage.Width;
            }
            if (sourceImage.Height < pixelSize)
            {
                pixelSize = sourceImage.Height;
            }

            using (IFastBitmap dest = FastBitmap.CreateCloneOf(sourceImage)) {
                using (IFastBitmap src = FastBitmap.Create(sourceImage as Bitmap)) {
                    FastBitmap.MixColors(dest, src, pixelSize);
                }

                Bitmap bmp = new Bitmap(dest.Width, dest.Height, sourceImage.PixelFormat);
                using (Graphics graphics = Graphics.FromImage(bmp)) {
                    dest.DrawTo(graphics, Point.Empty);
                }
                return(bmp);
            }
        }
Exemple #5
0
        public Image Blur(Image sourceImage, int radius)
        {
            if (sourceImage == null)
            {
                return(sourceImage);
            }

            using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(sourceImage)) {
                FastBitmapOperator.ApplyBoxBlur(fastBitmap, radius);
                Bitmap bmp = new Bitmap(sourceImage.Width, sourceImage.Height, sourceImage.PixelFormat);
                using (Graphics graphics = Graphics.FromImage(bmp)) {
                    fastBitmap.DrawTo(graphics, Point.Empty);
                }
                return(bmp);
            }
        }