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);
            }
        }
示例#2
0
        public static Bitmap Pixelate(Bitmap sourceImage, int pixelSize)
        {
            pixelSize = Math.Min(pixelSize, sourceImage.Width);
            pixelSize = Math.Min(pixelSize, sourceImage.Height);

            Bitmap result = sourceImage.CreateEmptyBitmap();

            using (IFastBitmap src = FastBitmap.Create(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height)))
                using (IFastBitmap dest = FastBitmap.Create(result))
                {
                    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 = ColorHelpers.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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

            return(result);
        }
示例#3
0
        public override bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails)
        {
            LOG.DebugFormat("Changing surface to grayscale!");
            using (IFastBitmap bbb = FastBitmap.Create(surface.Image as Bitmap)) {
                bbb.Lock();
                for (int y = 0; y < bbb.Height; y++)
                {
                    for (int x = 0; x < bbb.Width; x++)
                    {
                        Color color = bbb.GetColorAt(x, y);
                        int   luma  = (int)((0.3 * color.R) + (0.59 * color.G) + (0.11 * color.B));
                        color = Color.FromArgb(luma, luma, luma);
                        bbb.SetColorAt(x, y, color);
                    }
                }
            }

            return(true);
        }