private void button1_Click_1(object sender, EventArgs e) // Open image { button2.Visible = false; label2.Visible = false; numericUpDown1.Visible = false; button3.Visible = false; radioButton1.Visible = false; radioButton2.Visible = false; OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { OrigBmp = new Bitmap(openFileDialog1.FileName); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } else { return; } Point P = new Point(20, 126); label1.Location = P; label1.Text = "File " + openFileDialog1.FileName; label1.Visible = true; button2.Visible = true; label2.Visible = true; numericUpDown1.Visible = true; label3.Visible = true; label4.Visible = false; label5.Text = "Click 'Detect edges'"; label5.Visible = true; FileName = openFileDialog1.FileName; progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Step = 1; progressBar1.Visible = true; if (OrigBmp.Width < 300 || OrigBmp.Height < 300) { MessageBox.Show("The image " + FileName + " is too small: width=" + OrigBmp.Width + " height=" + OrigBmp.Height + ". No bicycle recognized."); return; } if (OrigBmp.PixelFormat == PixelFormat.Format8bppIndexed) { OrigIm = new CImage(OrigBmp.Width, OrigBmp.Height, 8); OrigIm.BitmapToImageOld(OrigBmp, this); } else if (OrigBmp.PixelFormat == PixelFormat.Format24bppRgb) { OrigIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); OrigIm.BitmapToImage(OrigBmp, this); if (OrigBmp.Width > 1200) // Resize { HelpIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); int Reduce = 2; if (OrigBmp.Width > 2400) { Reduce = 4; } HelpIm.FastAverageUni(OrigIm, Reduce / 2, this); width = (OrigBmp.Width + Reduce / 2) / Reduce; height = (OrigBmp.Height + Reduce / 2) / Reduce; OrigIm = new CImage(width, height, 24); OrigIm.Resize(HelpIm, OrigBmp.Width, OrigBmp.Height, 3, Reduce); //, ref width, ref height); } } else { MessageBox.Show("Form1: Inappropriate pixel format=" + OrigBmp.PixelFormat); return; } width = OrigIm.width; height = OrigIm.height; double ScaleX = (double)pictureBox2.Width / (double)OrigIm.width; double ScaleY = (double)pictureBox2.Height / (double)OrigIm.height; if (ScaleX < ScaleY) { Scale1 = ScaleX; } else { Scale1 = ScaleY; } marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; OrigIm.nLoop = 2; SigmaIm = new CImage(OrigIm.width, OrigIm.height, 24); pictureBox1.Image = OrigBmp; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Step = 1; OrigIm.denomProg = progressBar1.Maximum / progressBar1.Step; ExtremIm = new CImage(OrigIm.width, OrigIm.height, 24); EdgeIm = new CImage(OrigIm.width, OrigIm.height, 8); CombIm = new CImage(2 * OrigIm.width + 1, 2 * OrigIm.height + 1, 8); BmpPictBox2 = new Bitmap(width, height); g2Bmp = Graphics.FromImage(BmpPictBox2); pictureBox2.Image = BmpPictBox2; OPEN = true; }