private bool fix_orientiation() { bool flag = true; deskew(); flag = search_left_marker(0, 0, 20); if (flag) { flag = search_right_marker(img.Width / 2, 0, 20); } if (flag) { flag = search_bottom_marker(0, img.Size.Height / 2, 20); } /* * int percent = findcircle(x_lc, y_lc, width/2); * if (percent <= 5) * { * flag = false; * }*/ int diff_x = 0, diff_y = 0, n_width = width, n_height = height; diff_x = lc_x - 10; diff_y = lc_y - 10; try { img = cropAtRect(img, new Rectangle(lc_x, lc_y, rc_x + 20 - diff_x, bc_y + 20 - diff_y)); } catch (Exception ex) { MessageBox.Show("Aborting : " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } double percent = 0.0; if (img.Width >= width) { percent = calculation.percentageDecrease(img.Width, width); } else { percent = calculation.percentageIncrease(img.Width, width); } Size sz = calculation.increaseScale(img.Width, img.Height, percent); img = new Bitmap(img, new Size(width, height)); return(flag); }
private void sheet_designer_btn_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Image files | *.jpg; *.jpeg; *.jpe; *.jfif; *.png"; DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) // Test result. { file = openFileDialog1.FileName; imagePanel.Visible = true; nothing_lbl.Visible = false; save_btn.Visible = true; Stream BitmapStream = System.IO.File.Open(file, System.IO.FileMode.Open); Image imgage = Image.FromStream(BitmapStream); img = new Bitmap(imgage); imagePanel.BackgroundImage = img; imagePanel.BackgroundImageLayout = ImageLayout.Stretch; imagePanel.Width = imagePanel.BackgroundImage.Width; imagePanel.Height = imagePanel.BackgroundImage.Height; double decrease = calculate.percentageDecrease(imagePanel.BackgroundImage.Width, sheet.Width); Size size = calculate.decreaseScale(imagePanel.Width, imagePanel.Height, decrease); imagePanel.Size = size; imagePanel.Location = new Point(0, 0); data.update_template(template_id, size.Width, size.Height); Panel panel = new Panel(); Panel panel1 = new Panel(); Panel panel2 = new Panel(); imagePanel.Controls.Add(panel); panel.BackgroundImage = drawmarkers(m_width, m_height); panel.BackgroundImageLayout = ImageLayout.Zoom; panel.Size = new Size(m_width, m_height); panel.Location = new Point(m_x, m_y); imagePanel.Controls.Add(panel1); panel1.BackgroundImage = drawmarkers(m_width, m_height); panel1.BackgroundImageLayout = ImageLayout.Zoom; panel1.Size = new Size(m_width, m_height); panel1.Location = new Point(imagePanel.Width - m_x - m_width, m_y); imagePanel.Controls.Add(panel2); panel2.BackgroundImage = drawmarkers(m_width, m_height); panel2.BackgroundImageLayout = ImageLayout.Zoom; panel2.Size = new Size(m_width, m_height); panel2.Location = new Point(m_x, imagePanel.Height - m_y - m_height); data.insert_new_option(template_id, "Markers", "LC"); data.update_option(template_id, "Markers", "LC", "x_cor", m_x.ToString()); data.update_option(template_id, "Markers", "LC", "y_cor", m_y.ToString()); data.insert_new_option(template_id, "Markers", "RC"); data.update_option(template_id, "Markers", "RC", "x_cor", (imagePanel.Width - m_x - m_width).ToString()); data.update_option(template_id, "Markers", "RC", "y_cor", m_y.ToString()); data.insert_new_option(template_id, "Markers", "BC"); data.update_option(template_id, "Markers", "BC", "x_cor", m_x.ToString()); data.update_option(template_id, "Markers", "BC", "y_cor", (imagePanel.Height - m_y - m_height).ToString()); BitmapStream.Dispose(); editing = true; status_lbl.Text = "File Created"; } }
private void start_processing() { int count = files.Length; int i = 1; foreach (string file_load in files) { if (Path.GetExtension(file_load) == ".jpeg" || Path.GetExtension(file_load) == ".jpg" || Path.GetExtension(file_load) == ".JPG") { SetText("Processing file " + file_load + "\n------------------------------------------\n"); if (status_lbl2.InvokeRequired) { status_lbl2.Invoke(new Action(() => { status_lbl2.Text = "Processing File : " + i + " of " + count; })); } else { status_lbl2.Text = "Processing File : " + i + " of " + count; } SetBitmap(file_load); img = new Bitmap(file_load); calculation = new calculation_class(); double percent = 0.0; if (img.Width >= width) { percent = calculation.percentageDecrease(img.Width, width); } else { percent = calculation.percentageIncrease(img.Width, width); } Size sz = calculation.increaseScale(img.Width, img.Height, percent); img = resizeImage((Image)img, sz.Width, sz.Height); img = new Bitmap(img, new Size(width, height)); img = greyscale(img); if (!fix_orientiation()) { MessageBox.Show("Not Properly Aligned. Image Path : " + file_load); continue; } file = file_load; //img.Save(file_load+"PROCESSED"); // FOR DEBUGGING findname(); findroll(); findresult(); name = name.Trim(); questions = questions.Trim(new char[] { ',', ' ' }); if (roll == "") { roll = "00"; } dt.Rows.Add(name, roll, total, questions, options.Rows.Count * 5 ); name = ""; roll = ""; total = 0; questions = ""; img.Dispose(); i++; } } if (result_gridview.InvokeRequired) { result_gridview.Invoke(new Action(() => { result_gridview.DataSource = dt; status_lbl2.Visible = false; result_gridview.Visible = true; result_gridview.Refresh(); })); } else { result_gridview.DataSource = dt; status_lbl2.Visible = false; result_gridview.Visible = true; result_gridview.Refresh(); } if (save_result_txt.InvokeRequired) { save_result_txt.Invoke(new Action(() => { save_result_txt.Visible = true; save_result_btn.Visible = true; csv_btn.Visible = true; reset_btn.Visible = true; status_lbl.Text = "Processing Completed"; })); } else { save_result_txt.Visible = true; save_result_btn.Visible = true; csv_btn.Visible = true; reset_btn.Visible = true; status_lbl.Text = "Processing Completed"; } //result_gridview.DataSource = dt; }