public static void exportAsImage()
        {
            Bitmap image = new Bitmap(Data.imageLocation);

            int boxWidth  = image.Width / 5;
            int boxHeight = image.Height / 8;
            int margin    = boxHeight / 9;
            int center    = (image.Width / 2) - (boxWidth / 2);
            int template  = margin;

            for (int i = 0; i < 7; i++)
            {
                using (Graphics graphics = Graphics.FromImage(image))
                {
                    using (SolidBrush brush = new SolidBrush(Alchemy.hextoColor(Data.colors[i])))
                    {
                        graphics.FillRectangle(brush, center, template, boxWidth, boxHeight);

                        template += margin + boxHeight;
                    }
                }
            }
            image.Save("Exported Palette.bmp");
            System.Windows.Forms.MessageBox.Show("Image has been exported!");
        }
示例#2
0
        private void outputWindow_Load(object sender, EventArgs e)
        {
            pictureBox.ImageLocation = Data.imageLocation;

            panel1.BackColor = Alchemy.hextoColor(Data.colors[0]);
            label1.Text      = Data.colors[0];
            panel2.BackColor = Alchemy.hextoColor(Data.colors[1]);
            label2.Text      = Data.colors[1];
            panel3.BackColor = Alchemy.hextoColor(Data.colors[2]);
            label3.Text      = Data.colors[2];
            panel4.BackColor = Alchemy.hextoColor(Data.colors[3]);
            label4.Text      = Data.colors[3];
            panel5.BackColor = Alchemy.hextoColor(Data.colors[4]);
            label5.Text      = Data.colors[4];
            panel6.BackColor = Alchemy.hextoColor(Data.colors[5]);
            label6.Text      = Data.colors[5];
            panel7.BackColor = Alchemy.hextoColor(Data.colors[6]);
            label7.Text      = Data.colors[6];
        }
示例#3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (Data.imageLocation != "")
            {
                if (checkBox1.Checked)
                {
                    Data.threshold   = trackBar1.Value;
                    Data.resolution  = trackBar3.Value;
                    Data.compression = trackBar2.Value;
                    Data.accuracy    = trackBar4.Value;
                }
                else
                {
                    Data.threshold   = 50;
                    Data.resolution  = 600;
                    Data.compression = 50;
                    Data.accuracy    = 4;
                }


                // Rozpoczecie procesu
                List <string> outputColors = new List <string>();
                Bitmap        holder       = new Bitmap(Data.imageLocation);
                Bitmap        map          = new Bitmap(holder, Data.resolution, Data.resolution); //Tutaj bede jedne z paramatrow
                Alchemy.analyze(Pixelate.convert(map, new Rectangle(0, 0, map.Width, map.Height), 50), outputColors);

                for (int i = 0; i < 7; i++)
                {
                    Data.colors[i] = outputColors[i];
                }

                this.Hide();
                outputWindow outputWin = new outputWindow();
                outputWin.ShowDialog();
                this.Close();
            }
        }
示例#4
0
        //Alchemy class contains default analyzing algorithm

        public static void analyze(Bitmap map, List <string> outputTab)
        {
            List <Tint> inputTab = new List <Tint>();
            bool        control;

            // false = this color isn't on the list
            // true = this color is already on the list

            //Checking all pixels in a loop row by row
            for (int y = 0; y < map.Height; y += Data.accuracy)
            {
                for (int x = 0; x < map.Width; x += Data.accuracy)
                {
                    control = false;
                    if (inputTab.Count == 0)
                    {
                        inputTab.Add(new Tint(Alchemy.toHex(map.GetPixel(x, y))));
                    }
                    else
                    {
                        for (int i = 0; i < inputTab.Count; i++)
                        {
                            if (Alchemy.toHex(map.GetPixel(x, y)) == inputTab[i].printColor())
                            {
                                control = true;
                                inputTab[i].add();
                            }
                        }

                        if (!control)
                        {
                            inputTab.Add(new Tint(Alchemy.toHex(map.GetPixel(x, y))));
                        }
                    }
                }
            }

            //Sorting colors by number of occurences
            Sort.colorBubbleSort(inputTab);

            //inputTab = inputTab.OrderBy(x => x.getAmount()).ToList();
            //Linq okazał się wolniejszy

            //Removing colors that are too similar to each other
            Filter filter        = new Filter(Data.threshold);
            int    inputTabIndex = inputTab.Count - 2;
            bool   isGood;

            outputTab.Add(inputTab[inputTab.Count - 1].printColor());
            while (outputTab.Count < 7)
            {
                isGood = true;

                for (int y = 0; y < outputTab.Count; y++)
                {
                    if (filter.different(hextoColor(outputTab[y]), hextoColor(inputTab[inputTabIndex].printColor())))
                    {
                        isGood = false;
                    }
                }

                if (isGood)
                {
                    outputTab.Add(inputTab[inputTabIndex].printColor());
                    inputTabIndex--;
                }
                else
                {
                    inputTabIndex--;
                }
            }

            /// DEBUG ///
            for (int m = 0; m < outputTab.Count; m++)
            {
                Console.Out.WriteLine(outputTab[m]);
            }
        }