Exemplo n.º 1
0
        public static Image Outline(Image img, int borderSize, Color borderColor)
        {
            Bitmap result = img.CreateEmptyBitmap(borderSize * 2, borderSize * 2);

            ColorMatrix maskMatrix = new ColorMatrix();

            maskMatrix.Matrix00 = 0;
            maskMatrix.Matrix11 = 0;
            maskMatrix.Matrix22 = 0;
            maskMatrix.Matrix33 = 1;
            maskMatrix.Matrix40 = ((float)borderColor.R).Remap(0, 255, 0, 1);
            maskMatrix.Matrix41 = ((float)borderColor.G).Remap(0, 255, 0, 1);
            maskMatrix.Matrix42 = ((float)borderColor.B).Remap(0, 255, 0, 1);

            using (img)
                using (Image shadow = maskMatrix.Apply(img))
                    using (Graphics g = Graphics.FromImage(result))
                    {
                        for (int i = 0; i <= borderSize * 2; i++)
                        {
                            g.DrawImage(shadow, new Rectangle(i, 0, shadow.Width, shadow.Height));
                            g.DrawImage(shadow, new Rectangle(i, borderSize * 2, shadow.Width, shadow.Height));
                            g.DrawImage(shadow, new Rectangle(0, i, shadow.Width, shadow.Height));
                            g.DrawImage(shadow, new Rectangle(borderSize * 2, i, shadow.Width, shadow.Height));
                        }

                        g.DrawImage(img, new Rectangle(borderSize, borderSize, img.Width, img.Height));
                    }

            return(result);
        }
Exemplo n.º 2
0
        public static Bitmap ConvertBlackAndWhite(Bitmap Image, Boolean invert)
        {
            ColorMatrix TempMatrix = new ColorMatrix();
            float       v          = 9;

            float[][] FloatColorMatrixB =
            {
                new float[] { v,  v,  v,  0, 0 },
                new float[] { v,  v,  v,  0, 0 },
                new float[] { v,  v,  v,  0, 0 },
                new float[] {  0,  0,  0, v, 0 },
                new float[] { -v, -v, -v, 0, v }
            };

            float[][] FloatColorMatrixI =
            {
                new float[] { -1,  0,  0, 0, 0 },
                new float[] {  0, -1,  0, 0, 0 },
                new float[] {  0,  0, -1, 0, 0 },
                new float[] {  0,  0,  0, 1, 0 },
                new float[] {  1,  1,  1, 1, 1 }
            };
            if (invert == false)
            {
                TempMatrix.Matrix = FloatColorMatrixB;
            }
            else
            {
                TempMatrix.Matrix = FloatColorMatrixI;
            }

            return(TempMatrix.Apply(Image));
        }
Exemplo n.º 3
0
        public static Bitmap AddShadow(Image sourceImage, float opacity, int size, float darkness, Color color, Point offset)
        {
            Image shadowImage = null;

            try
            {
                shadowImage = sourceImage.CreateEmptyBitmap(size * 2, size * 2);

                ColorMatrix maskMatrix = new ColorMatrix();
                maskMatrix.Matrix00 = 0;
                maskMatrix.Matrix11 = 0;
                maskMatrix.Matrix22 = 0;
                maskMatrix.Matrix33 = opacity;
                maskMatrix.Matrix40 = ((float)color.R).Remap(0, 255, 0, 1);
                maskMatrix.Matrix41 = ((float)color.G).Remap(0, 255, 0, 1);
                maskMatrix.Matrix42 = ((float)color.B).Remap(0, 255, 0, 1);

                Rectangle shadowRectangle = new Rectangle(size, size, sourceImage.Width, sourceImage.Height);
                maskMatrix.Apply(sourceImage, shadowImage, shadowRectangle);

                if (size > 0)
                {
                    Blur((Bitmap)shadowImage, size);
                }

                if (darkness > 1)
                {
                    ColorMatrix alphaMatrix = new ColorMatrix();
                    alphaMatrix.Matrix33 = darkness;

                    Image shadowImage2 = alphaMatrix.Apply(shadowImage);
                    shadowImage.Dispose();
                    shadowImage = shadowImage2;
                }

                Bitmap result = shadowImage.CreateEmptyBitmap(Math.Abs(offset.X), Math.Abs(offset.Y));

                using (Graphics g = Graphics.FromImage(result))
                {
                    g.SetHighQuality();
                    g.DrawImage(shadowImage, Math.Max(0, offset.X), Math.Max(0, offset.Y), shadowImage.Width, shadowImage.Height);
                    g.DrawImage(sourceImage, Math.Max(size, -offset.X + size), Math.Max(size, -offset.Y + size), sourceImage.Width, sourceImage.Height);
                }

                return(result);
            }
            finally
            {
                if (sourceImage != null)
                {
                    sourceImage.Dispose();
                }
                if (shadowImage != null)
                {
                    shadowImage.Dispose();
                }
            }
        }
        /// <summary>
        /// Image processing module
        /// </summary>
        /// <param name="Image"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static Bitmap AdjustBrightness(Bitmap Image, int Value)
        {
            float       FinalValue = (float)Value / 255.0f;
            ColorMatrix TempMatrix = new ColorMatrix();

            TempMatrix.Matrix = new float[][] {
                new float[] { 1, 0, 0, 0, 0 },
                new float[] { 0, 1, 0, 0, 0 },
                new float[] { 0, 0, 1, 0, 0 },
                new float[] { 0, 0, 0, 1, 0 },
                new float[] { FinalValue, FinalValue, FinalValue, 1, 1 }
            };
            return(TempMatrix.Apply(Image));
        }
Exemplo n.º 5
0
        public override Image Apply(Image img)
        {
            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new float[] { Rr, Gr, Br, Ar, 0 },
                new float[] { Rg, Gg, Bg, Ag, 0 },
                new float[] { Rb, Gb, Bb, Ab, 0 },
                new float[] { Ra, Ga, Ba, Aa, 0 },
                new float[] { Ro, Go, Bo, Ao, 1 }
            });

            using (img)
            {
                return(colorMatrix.Apply(img));
            }
        }
Exemplo n.º 6
0
        public override Bitmap Apply(Bitmap bmp)
        {
            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new float[] { Rr, Gr, Br, Ar, 0 },
                new float[] { Rg, Gg, Bg, Ag, 0 },
                new float[] { Rb, Gb, Bb, Ab, 0 },
                new float[] { Ra, Ga, Ba, Aa, 0 },
                new float[] { Ro, Go, Bo, Ao, 1 }
            });

            using (bmp)
            {
                return(colorMatrix.Apply(bmp));
            }
        }