Example #1
0
 public void SetColorMatrices_ColorMatrix_Null()
 {
     using (ImageAttributes ia = new ImageAttributes()) {
         ia.SetColorMatrices(global_color_matrix, null);
         ia.SetColorMatrices(global_color_matrix, null, ColorMatrixFlag.Default);
         ia.SetColorMatrices(global_color_matrix, null, ColorMatrixFlag.SkipGrays);
     }
 }
Example #2
0
 public void SetColorMatrices_InvalidType()
 {
     using (ImageAttributes ia = new ImageAttributes())
     {
         ia.SetColorMatrices(global_color_matrix, global_color_matrix, ColorMatrixFlag.Default, (ColorAdjustType)Int32.MinValue);
     }
 }
Example #3
0
 public void SetColorMatrices_InvalidFlags()
 {
     using (ImageAttributes ia = new ImageAttributes())
     {
         ia.SetColorMatrices(global_color_matrix, global_color_matrix, (ColorMatrixFlag)Int32.MinValue);
     }
 }
Example #4
0
 public void SetColorMatrices_ColorMatrix_Null_AltGrays()
 {
     using (ImageAttributes ia = new ImageAttributes())
     {
         ia.SetColorMatrices(global_color_matrix, null, ColorMatrixFlag.AltGrays);
     }
 }
Example #5
0
 public void SetColorMatrices_Null_ColorMatrix()
 {
     using (ImageAttributes ia = new ImageAttributes())
     {
         ia.SetColorMatrices(null, global_color_matrix);
     }
 }
Example #6
0
 public void SetColorMatrices_InvalidType()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (ImageAttributes ia = new ImageAttributes()) {
             ia.SetColorMatrices(global_color_matrix, global_color_matrix, ColorMatrixFlag.Default, (ColorAdjustType)Int32.MinValue);
         }
     });
 }
Example #7
0
 public void SetColorMatrices_ColorMatrix_Null_AltGrays()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (ImageAttributes ia = new ImageAttributes()) {
             ia.SetColorMatrices(global_color_matrix, null, ColorMatrixFlag.AltGrays);
         }
     });
 }
Example #8
0
 public void SetColorMatrices_Null_ColorMatrix()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (ImageAttributes ia = new ImageAttributes()) {
             ia.SetColorMatrices(null, global_color_matrix);
         }
     });
 }
Example #9
0
 private static Color ProcessColorMatrices(Color color, ColorMatrix colorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag flags, ColorAdjustType type)
 {
     using (Bitmap bmp = new Bitmap(64, 64)) {
         using (Graphics gr = Graphics.FromImage(bmp)) {
             ImageAttributes imageAttr = new ImageAttributes();
             bmp.SetPixel(0, 0, color);
             imageAttr.SetColorMatrices(colorMatrix, grayMatrix, flags, type);
             gr.DrawImage(bmp, new Rectangle(0, 0, 64, 64), 0, 0, 64, 64, GraphicsUnit.Pixel, imageAttr);
             return(bmp.GetPixel(0, 0));
         }
     }
 }
Example #10
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }
            string path_app = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
            string path     = args[0];

            if (!Directory.Exists(path))
            {
                return;
            }
            string path_done = path + Path.DirectorySeparatorChar + "_watermark";

            if (!Directory.Exists(path_done))
            {
                Directory.CreateDirectory(path_done);
            }

            ColorMatrix color_matrix = new ColorMatrix();

            color_matrix.Matrix33 = 0.3f; // watermark opacity
            ImageAttributes image_attributes = new ImageAttributes();

            image_attributes.SetColorMatrices(color_matrix, null);

            // add an image file to resource as watermark
            using (Bitmap watermark = DrawaliveWatermark.Properties.Resources.watermark)
            {
                foreach (string filename in Directory.GetFiles(path))
                {
                    string ext = Path.GetExtension(filename).ToLower();
                    if (".jpg".CompareTo(ext) != 0)
                    {
                        continue;
                    }
                    Console.WriteLine(filename);
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(filename))
                    {
                        Watermark(bmp, watermark, image_attributes);
                        bmp.Save(path_done +
                                 Path.DirectorySeparatorChar +
                                 Path.GetFileName(filename), ImageFormat.Jpeg);
                    }
                }
            }
        }
Example #11
0
 public void SetColorMatrices_InvalidFlags()
 {
     using (ImageAttributes ia = new ImageAttributes()) {
         Assert.Throws <ArgumentException> (() => ia.SetColorMatrices(global_color_matrix, global_color_matrix, (ColorMatrixFlag)Int32.MinValue));
     }
 }