private void button6_Click(object sender, EventArgs e) { int width = Convert.ToInt16(textBox2.Text); int height = Convert.ToInt16(textBox3.Text); //Смещение системы координат в точку клика курсором // var g = pictureBox2.CreateGraphics(); // g.TranslateTransform(width, height); int pY, pX, group = 0; Color clr; ConvertImg_box.Refresh(); Bitmap nImg = new Bitmap(LoadImg_box.Image.Width, LoadImg_box.Image.Height); //Считываем и записываем координаты в список for (pY = 0; pY < LoadImg_box.Image.Height; pY++) { for (pX = 0; pX < LoadImg_box.Image.Width; pX++) { LoadImg_box.Refresh(); clr = (LoadImg_box.Image as Bitmap).GetPixel(pX, pY); if ((clr.R.Equals(0)) && (clr.G.Equals(0)) && (clr.B.Equals(0))) { group = group + 1; List <List <int> > list = new List <List <int> >(); List <int> array = new List <int>(); array.Add(group); array.Add(pX); array.Add(pY); list.Add(array); } if (pixel_value(pX, pY) == 1) { nImg.SetPixel(pX, pY, Color.Black); } else { nImg.SetPixel(pX, pY, Color.White); } ConvertImg_box.Image = nImg; } } }
private void LoadImg_btn_Click(object sender, EventArgs e) //Загружаем с диска изображение в бокс. { Bitmap image; Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "Image files (*.png; *.jpeg; *.bmp)|*.png; *.jpeg; *.bmp|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { if ((myStream = openFileDialog1.OpenFile()) != null) { using (myStream) { image = new Bitmap(openFileDialog1.FileName); // pictureBox3.Width = image.Width; // pictureBox3.Height = image.Height; LoadImg_box.Image = image; LoadImg_box.Invalidate(); // Insert code to read the stream here. } } } catch (Exception ex) { DialogResult rezult = MessageBox.Show("Невозможно открыть выбранный файл", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }