Пример #1
0
 private void BtnGray_Click(object sender, EventArgs e)
 {
     manipulated         = ImageManipulations.MakeGray(original);
     currentManipulation = "_grayscale";
     pbManipulated.Image = manipulated;
     manipulationMade    = true;
 }
Пример #2
0
        public void GrayscaleWorks()
        {
            Color red   = Color.FromArgb(255, 0, 0);
            Color green = Color.FromArgb(0, 255, 0);
            Color blue  = Color.FromArgb(0, 0, 255);
            Color white = Color.FromArgb(255, 255, 255);

            Color[,] originalColors =
            {
                { red,  green },
                { blue, white }
            };

            Bitmap original = CreateImage(2, 2, originalColors);
            Bitmap actual   = ImageManipulations.MakeGray(original);
            bool   isGray   = false;

            for (int y = 0; y < actual.Height; y++)
            {
                for (int x = 0; x < actual.Width; x++)
                {
                    // Om värdena för R, G och B hos en pixel har samma värde ska den anses vara grå.
                    if (actual.GetPixel(x, y).R == actual.GetPixel(x, y).G&&
                        actual.GetPixel(x, y).R == actual.GetPixel(x, y).B)
                    {
                        isGray = true;
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            }
            Assert.IsTrue(isGray);
        }
Пример #3
0
        static void Main(string[] args)
        {
            string path = null;

            if (args.Length > 0)
            {
                path = args[0];
            }
            else
            {
                bool   retry        = false;
                string message      = "Please enter the path to your image: ";
                string retryMessage = "\nCould not find image, please try again: ";

                while (!File.Exists(path))
                {
                    Console.Write(retry ? retryMessage : message);
                    path  = Console.ReadLine();
                    retry = true;
                }
            }

            Console.WriteLine("Working...");

            Bitmap original;

            try
            {
                // Kolla om filen är en bildfil och tilldela isf den till "original"
                original = new Bitmap(path);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("The file is not an acceptable format.");
                return;
            }

            if (original.Width >= 5000 || original.Height >= 5000)
            {
                Console.WriteLine("The image cannot be over 5000 pixels in height or width.");
                return;
            }

            Bitmap negative = ImageManipulations.MakeNegative(original);

            negative.Save(PathManipulations.EditFileName(path, "_negative"));
            Console.WriteLine("Negative saved");

            Bitmap gray = ImageManipulations.MakeGray(original);

            gray.Save(PathManipulations.EditFileName(path, "_grayscale"));
            Console.WriteLine("Grayscale saved");

            Bitmap blurry = ImageManipulations.MakeBlurry(original);

            blurry.Save(PathManipulations.EditFileName(path, "_blurred"));
            Console.WriteLine("The blurry image saved");

            // Om vi inte har anledning att misstänka att en server använder programmet,
            // så låt den eventuella användaren läsa eventuella meddelanden innan programmet avslutas.
            if (args.Length == 0)
            {
                Console.WriteLine("\nPress any key to exit...");
                Console.ReadKey();
            }
        }