public Form1()
        {
            InitializeComponent();
            pictureBox1.Image = Image.FromFile("Images/kot2.jpg");


            bitmap = new Bitmap("Images/kot2.jpg");
            calculateTables();
            childForm = new ChildForm(bitmap.Width, bitmap.Height, bitmap, cyanValues, magentaValues, yellowValues, blackValues);
            childForm.Show();
            SetUpTable();
            pictureBox3.Invalidate();
        }
Esempio n. 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter             = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
            dialog.InitialDirectory   = AppDomain.CurrentDomain.BaseDirectory + @"Images";
            dialog.AutoUpgradeEnabled = true;
            dialog.Title = "Please select an image.";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                bitmap = new Bitmap(@dialog.FileName);
                clampBitmap(pictureBox1.Width, pictureBox1.Height);
                pictureBox1.Image = bitmap;
                childForm.Close();
                childForm = new ChildForm(bitmap.Width, bitmap.Height, bitmap, cyanValues, magentaValues, yellowValues, blackValues);
                childForm.Show();
            }
        }
        private void button10_Click(object sender, EventArgs e)
        {
            int a      = 500;
            int b      = 800;
            int border = 20;

            Color[,] colorToPaint = new Color[b, a];
            for (int i = 0; i < b; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    colorToPaint[i, j] = Color.FromArgb(255, 255, 255);
                }
            }
            for (int i = 0; i < border; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    colorToPaint[i, j] = Color.FromArgb(0, 0, 0);
                }
            }
            for (int i = b - border; i < b; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    colorToPaint[i, j] = Color.FromArgb(0, 0, 0);
                }
            }
            for (int i = 0; i < b; i++)
            {
                for (int j = 0; j < border; j++)
                {
                    colorToPaint[i, j] = Color.FromArgb(0, 0, 0);
                }
            }
            for (int i = 0; i < b; i++)
            {
                for (int j = a - border; j < a; j++)
                {
                    colorToPaint[i, j] = Color.FromArgb(0, 0, 0);
                }
            }

            int r       = 180;
            int small_r = 30;
            int deg     = 0;
            int s       = 1;
            int v       = 1;

            for (int i = 0; i < 18; i++)
            {
                int   angle    = deg + i * 20;
                Color col      = ColorFromHSV(angle, s, v);
                int   x_center = b / 2 + (int)(r * Math.Sin(DegreeToRadian((double)angle)));
                int   y_center = a / 2 + (int)(r * Math.Cos(DegreeToRadian((double)angle)));
                for (int j = x_center - small_r; j < x_center + small_r; j++)
                {
                    for (int k = y_center - small_r; k < y_center + small_r; k++)
                    {
                        if (Math.Pow(k - y_center, 2) + Math.Pow(j - x_center, 2) <= Math.Pow(small_r, 2))
                        {
                            colorToPaint[j, k] = col;
                        }
                    }
                }
            }

            Bitmap processedBitmap = new Bitmap(b, a);

            unsafe
            {
                BitmapData bitmapData = processedBitmap.LockBits(new Rectangle(0, 0, processedBitmap.Width, processedBitmap.Height), ImageLockMode.ReadWrite, processedBitmap.PixelFormat);

                int   bytesPerPixel  = System.Drawing.Bitmap.GetPixelFormatSize(processedBitmap.PixelFormat) / 8;
                int   heightInPixels = bitmapData.Height;
                int   widthInBytes   = bitmapData.Width * bytesPerPixel;
                byte *PtrFirstPixel  = (byte *)bitmapData.Scan0;

                Parallel.For(0, heightInPixels, y =>
                {
                    byte *currentLine = PtrFirstPixel + (y * bitmapData.Stride);
                    for (int x = 0; x < widthInBytes; x = x + bytesPerPixel)
                    {
                        currentLine[x]     = colorToPaint[x / 4, y].B;
                        currentLine[x + 1] = colorToPaint[x / 4, y].G;
                        currentLine[x + 2] = colorToPaint[x / 4, y].R;
                        currentLine[x + 3] = colorToPaint[x / 4, y].A;
                    }
                });
                processedBitmap.UnlockBits(bitmapData);
            }

            pictureBox1.Image = processedBitmap;
            childForm.Close();
            childForm = new ChildForm(processedBitmap.Width, processedBitmap.Height, processedBitmap, cyanValues, magentaValues, yellowValues, blackValues);
            childForm.Show();
        }