コード例 #1
0
ファイル: Program.cs プロジェクト: ricardovws/ColorChanger
        private static void SetGrayscale(PictureParameters picture)
        {
            //find the average of them(a, r, g, b)
            int avg = (picture.ARGB_r + picture.ARGB_g + picture.ARGB_b) / 3;

            //set a new pixel value for them:
            picture.Picture.SetPixel(picture.positionX, picture.positionY, Color.FromArgb(picture.ARGB_a, avg, avg, avg));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ricardovws/ColorChanger
        private static void SetNegative(PictureParameters picture)
        {
            picture.ARGB_r = 255 - picture.ARGB_r;
            picture.ARGB_g = 255 - picture.ARGB_g;
            picture.ARGB_b = 255 - picture.ARGB_b;

            //set a new pixel value for them:
            picture.Picture.SetPixel(picture.positionX, picture.positionY, Color.FromArgb(picture.ARGB_a, picture.ARGB_r, picture.ARGB_g, picture.ARGB_b));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ricardovws/ColorChanger
 private static void SetBluescale(PictureParameters picture)
 {
     //set a new pixel value for them:
     picture.Picture.SetPixel(picture.positionX, picture.positionY, Color.FromArgb(picture.ARGB_a, 0, 0, picture.ARGB_b));
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: ricardovws/ColorChanger
        static void Main(string[] args)
        {
            bool keepWorking = true;

            while (keepWorking == true)
            {
                Console.Clear();
                Console.WriteLine("Hey there! :)");
                Console.WriteLine();
                Console.WriteLine("Please, insert the path of the image that you would like to change the colors:");
                Console.WriteLine();
                Console.WriteLine();
                ConsoleColor aux = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(@"e.g. -> path: C:\Users\Joaquim\Downloads\YOUR_PICTURE.JPEG");
                Console.ForegroundColor = aux;
                Console.WriteLine();
                Console.WriteLine();
                //Receive the path
                Console.Write("path: ");
                var path = Console.ReadLine();

                try
                {
                    //Read the image and check the path:
                    Bitmap bmp = new Bitmap(path);

                    Console.Clear();
                    Console.WriteLine("Alright! And now...What kind of color changing do you prefer?");
                    Console.WriteLine();
                    Console.WriteLine("Type the number of your choice:");
                    Console.WriteLine();


                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine("#1 - Grayscale");

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("#2 - Red");

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("#3 - Green");

                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("#4 - Blue");

                    Console.BackgroundColor = ConsoleColor.White;
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.WriteLine("#5 - Negative");

                    Console.ResetColor();

                    Console.WriteLine();
                    Console.Write("Your choice is: ");
                    var option = Console.ReadLine();
                    Console.Clear();

                    //Get the imagem dimensions
                    int witdh  = bmp.Width;
                    int height = bmp.Height;

                    //Pixel color
                    Color p;

                    //Set standard status message after export file
                    Messages messages     = new Messages();
                    string   finalMessage = messages.successfulMessage;


                    //starting pixel setting...
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < witdh; x++)
                        {
                            //get pixel value
                            p = bmp.GetPixel(x, y);

                            //extract each pixel component ARGB
                            int a = p.A;
                            int r = p.R;
                            int g = p.G;
                            int b = p.B;

                            PictureParameters pic = new PictureParameters(bmp, x, y, a, r, g, b);

                            //#1 - Grayscale
                            if (option == "1")
                            {
                                SetGrayscale(pic);
                            }
                            //#2 - Red
                            else if (option == "2")
                            {
                                SetRedscale(pic);
                            }
                            //#3 - Green
                            else if (option == "3")
                            {
                                SetGreenscale(pic);
                            }
                            //#4 - Blue
                            else if (option == "4")
                            {
                                SetBluescale(pic);
                            }
                            //#5 - Negative
                            else if (option == "5")
                            {
                                SetNegative(pic);
                            }
                            else
                            {
                                finalMessage = messages.errorMessage;
                            }
                        }
                    }


                    if (finalMessage == messages.successfulMessage)
                    {
                        //Asking about file name:
                        Console.WriteLine("The file will be exported to the same file's original path.");
                        Console.WriteLine();
                        Console.WriteLine("Almost there! Please, just write the file's name: ");
                        Console.Write("File's name: ");
                        var fileName = Console.ReadLine();
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Just wait, please...");

                        //Export file
                        ExportFile(bmp, path, fileName);
                    }

                    //Return status and finish task!
                    Console.WriteLine(finalMessage);
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("Would you like to try with another one?");
                    Console.WriteLine("Type 'y' to yes and anything else to 'no':");
                    var answer = Console.ReadLine();
                    if (answer != "y")
                    {
                        keepWorking = false;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Oups! There is an error here:");
                    Console.WriteLine(e.Message);
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("Would you like to try again?");
                    Console.WriteLine("Type 'y' to yes and anything else to 'no':");
                    var answer = Console.ReadLine();
                    if (answer != "y")
                    {
                        keepWorking = false;
                    }
                }
            }
        }