private bool ShowImage(PictureBox display, EImageBW8 image) { bool reSuccess = false; try { Bitmap bmp = new Bitmap(image.Width, image.Height); image.Draw(Graphics.FromImage(bmp), zoomX, zoomY, panX - mouseX, panY - mouseY); if (display.InvokeRequired) { display.Invoke(new Action(() => { display.BackgroundImage = bmp; })); } else { display.BackgroundImage = bmp; } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool ShowTrainImage(PictureBox display, EImageBW8 trainImage) { bool reSuccess = false; try { float scalingRatio = ScalingRatio(trainImage, display); Bitmap bmp = new Bitmap(display.Width, display.Height); trainImage.Draw(Graphics.FromImage(bmp), scalingRatio); if (display.InvokeRequired) { display.Invoke(new Action(() => { display.BackgroundImage = bmp; })); } else { display.BackgroundImage = bmp; } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private void ShowImage(EImageBW8 img, PictureBox pb) { try { Bitmap bmp; bmp = new Bitmap(pb.Width, pb.Height); //計算Picturebox與顯示影像的比例,以便將影像縮放並且完整呈現到picturebox上。 float PictureBoxSizeRatio = (float)pb.Width / pb.Height; float ImageSizeRatio = (float)img.Width / img.Height; if (ImageSizeRatio > PictureBoxSizeRatio) { ScalingRatio = (float)pb.Width / img.Width; } else { ScalingRatio = (float)pb.Height / img.Height; } EBW8ScaleRatio = ScalingRatio; //記錄此比例供繪製輪廓軌跡使用 //委派 if (pb.InvokeRequired) { pb.Invoke(new MethodInvoker(delegate() { img.Draw(Graphics.FromImage(bmp), ScalingRatio); pb.BackgroundImage = bmp; })); } else { //先將EImageC24畫在bitmap模式的圖檔 img.Draw(Graphics.FromImage(bmp), ScalingRatio); //再由Picturebox取得bitmap pb.BackgroundImage = bmp; } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void ShowImage(EImageBW8 img, PictureBox pb) { try { Bitmap bmp; bmp = new Bitmap(pb.Width, pb.Height); float PictureBoxSizeRatio = (float)pb.Width / pb.Height; float ImageSizeRatio = (float)img.Width / img.Height; if (ImageSizeRatio > PictureBoxSizeRatio) { ScalingRatio = (float)pb.Width / img.Width; } else { ScalingRatio = (float)pb.Height / img.Height; } if (pb.InvokeRequired) { pb.Invoke(new MethodInvoker(delegate() { img.Draw(Graphics.FromImage(bmp), ScalingRatio); pb.Image = bmp; })); } else { img.Draw(Graphics.FromImage(bmp), ScalingRatio); pb.Image = bmp; } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void excelToolStripMenuItem_Click(object sender, EventArgs e) { Excel_APP1 = new Excel.Application(); Excel_WB1 = Excel_APP1.Workbooks.Add(); Excel_WS1 = new Excel.Worksheet(); saveFileDialog1.Filter = "Excel|*.xlsx"; saveFileDialog1.Title = "Save a Excel"; Excel_WS1 = Excel_WB1.Worksheets[1]; Excel_WS1.Name = "Data"; Excel_APP1.Cells[1, 1] = "圖片(.jpg)"; Excel_APP1.Cells[1, 2] = "Profile下"; Excel_APP1.Cells[1, 3] = "Profile上"; OriginalImg1.Load(files[0]); /*============================計算scaling ratio============================*/ float PictureBoxSizeRatio = (float)pbImg1.Width / pbImg1.Height; float ImageSizeRatio = (float)OriginalImg1.Width / OriginalImg1.Height; if (ImageSizeRatio > PictureBoxSizeRatio) { ScalingRatio = (float)pbImg1.Width / OriginalImg1.Width; } else { ScalingRatio = (float)pbImg1.Height / OriginalImg1.Height; } /*=========================================================================*/ for (int i = 0; i < FileListBox.Items.Count; i++) { FileListBox.SelectedIndex = i; FileListBox.Refresh(); OriginalImg1.Load(files[i]); OriginalImg1.Draw(pbImg1.CreateGraphics(), ScalingRatio); //EC24Image2.SetSize(EC24Image1); //EasyImage.Oper(EArithmeticLogicOperation.Copy, new EC24(0, 0, 0), EC24Image2); //EC24Image1.ColorSystem = EColorSystem.Rgb; //EColorLookup1.ConvertFromRgb(EColorSystem.Yiq); //EColorLookup1.Transform(EC24Image1, EC24Image2); //EC24Image2.Draw(pbImg2.CreateGraphics(), ScalingRatio); GrayImg1.SetSize(OriginalImg1); EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1); EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階 //EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg1); //EasyImage.Threshold(GrayImg1, GrayImg1, 56); //EasyImage.OpenBox(GrayImg1, GrayImg1, settings.set_value_3()); GrayImg1.Draw(pbImg2.CreateGraphics(), ScalingRatio); EasyImage.ImageToLineSegment(GrayImg1, In, 1485, 700, 1683, 700); //設定車子進入的偵測線,判斷車子是否準備進來 EasyImage.ImageToLineSegment(GrayImg1, Out, 1485, 400, 1683, 400); //設定車子出去的偵測線,判斷車子是否準備出去 Excel_APP1.Cells[2 + i, 1] = Path.GetFileNameWithoutExtension(files[i]); Excel_APP1.Cells[2 + i, 2] = getProfileValueSum(In); Excel_APP1.Cells[2 + i, 3] = getProfileValueSum(Out); //Console.WriteLine(files[i]); } if (saveFileDialog1.ShowDialog() == DialogResult.OK && saveFileDialog1.FileName != "") { Excel_WB1.SaveAs(saveFileDialog1.FileName); } Excel_WS1 = null; Excel_WB1.Close(); Excel_WB1 = null; Excel_APP1.Quit(); Excel_APP1 = null; }