Exemplo n.º 1
0
        private Bitmap ConvertToSepia(Bitmap bitmap)
        {
            ColorMatrix cm = new ColorMatrix(new float[][] {
                new float[] { 0.393f, 0.349f, 0.272f, 0, 0 },
                new float[] { 0.769f, 0.686f, 0.534f, 0, 0 },
                new float[] { 0.189f, 0.168f, 0.131f, 0, 0 },
                new float[] { 0, 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 0, 1 }
            });

            return(ImageHelper.ApplyColorMatrix(bitmap, cm));
        }
        protected Bitmap Warm(Bitmap bitmap, float val)
        {
            ColorMatrix cm = new ColorMatrix(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[] { val, 0, -val, 0, 1 }
            });

            return(ImageHelper.ApplyColorMatrix(bitmap, cm));
        }
Exemplo n.º 3
0
        public static Bitmap AdjustBrightness(float bf, float cf, Bitmap bitmap)
        {
            ColorMatrix bm = new ColorMatrix(new float[][] {
                new float[] { 1f, 0f, 0f, 0f, 0f },
                new float[] { 0f, 1f, 0f, 0f, 0f },
                new float[] { 0f, 0f, 1f, 0f, 0f },
                new float[] { 0f, 0f, 0f, 1f, 0f },
                new float[] { bf, bf, bf, 1f, 1f }
            });

            //Create the contrast matrix.  Note, the last row offsets the colors by .001 to avoid
            //arithmetic overflows that cause dramatically incorrect colors.
            //Thanks to Bob Powell for that tip: http://www.bobpowell.net/image_contrast.htm
            ColorMatrix cm = new ColorMatrix(new float[][] {
                new float[] { cf, 0f, 0f, 0f, 0f },
                new float[] { 0f, cf, 0f, 0f, 0f },
                new float[] { 0f, 0f, cf, 0f, 0f },
                new float[] { 0f, 0f, 0f, 1f, 0f },
                new float[] { 0.001f, 0.001f, 0.001f, 0f, 1f }
            });


            ColorMatrix adjust = null;

            if (bf != 0)
            {
                adjust = bm;
            }
            if (cf != 1)
            {
                if (adjust != null)
                {
                    adjust = ImageUtils.Multiply(adjust, cm);
                }
                else
                {
                    adjust = cm;
                }
            }

            if (adjust != null)
            {
                return(ImageHelper.ApplyColorMatrix(bitmap, adjust));
            }
            else
            {
                return(bitmap);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert to a black and white image.
        /// Based on image processing algorithm from Paul Haeberli.
        /// http://www.sgi.com/misc/grafica/matrix/
        /// </summary>
        /// <param name="bitmap"></param>
        private Bitmap ConvertToBlackAndWhite(Bitmap bitmap)
        {
            float       rwgt = 0.3086f;
            float       gwgt = 0.6094f;
            float       bwgt = 0.0820f;
            ColorMatrix cm   = new ColorMatrix(new float[][] {
                new float[] { rwgt, rwgt, rwgt, 0f, 0f },
                new float[] { gwgt, gwgt, gwgt, 0f, 0f },
                new float[] { bwgt, bwgt, bwgt, 0f, 0f },
                new float[] { 0f, 0f, 0f, 1f, 0f },
                new float[] { 0f, 0f, 0f, 0f, 1f }
            });

            return(ImageHelper.ApplyColorMatrix(bitmap, cm));
        }
Exemplo n.º 5
0
        private Bitmap Saturate(Bitmap bitmap)
        {
            float a, b, c, d, e, f;
            float saturation;

            saturation = 1.65f;
            a          = (0.3086f * (1 - saturation)) + saturation;
            b          = (0.3086f * (1 - saturation));
            c          = (0.6094f * (1 - saturation));
            d          = (0.6094f * (1 - saturation)) + saturation;
            e          = (0.0820f * (1 - saturation));
            f          = (0.0820f * (1 - saturation)) + saturation;

            ColorMatrix cm = new ColorMatrix(new float[][] {
                new float[] { a, b, b, 0, 0 },
                new float[] { c, d, c, 0, 0 },
                new float[] { e, e, f, 0, 0 },
                new float[] { 0, 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 0, 1 }
            });

            return(ImageHelper.ApplyColorMatrix(bitmap, cm));
        }