public void saveResult(DateTime dateTime, Image ICam0, Image ICam1, Image ICam2, Image ICam3) { Global.Paint paint_NG = new Global.Paint { brush = new SolidBrush(Color.Red), Font = new Font("Microsoft YaHei UI", 20, FontStyle.Bold), pen = new Pen(Color.Red, 3) }; Global.Paint paint_OK = new Global.Paint { brush = new SolidBrush(Color.Green), Font = new Font("Microsoft YaHei UI", 20, FontStyle.Bold), pen = new Pen(Color.Green, 3) }; Global.Paint paint = paint_NG; Bitmap resultBitmap = new Bitmap(ICam0.Size.Width * 2, ICam0.Size.Height * 2); using (var g = Graphics.FromImage(resultBitmap)) { g.DrawImage(ICam0, 0, 0); g.DrawImage(ICam1, ICam0.Width, 0); g.DrawImage(ICam2, 0, ICam0.Height); g.DrawImage(ICam3, ICam0.Width, ICam0.Height); RectangleF[] rectangleF = new RectangleF[1]; for (int i = 0; i < modelSteps.Count; i++) { if (modelSteps[i].Result == Global.ICOP_tester_OK) { paint = paint_OK; } else { paint = paint_NG; } switch (modelSteps[i].Position) { case Global.Positions.ICam0: rectangleF[0] = modelSteps[i].ForDrawResult(ICam0); rectangleF[0].X = rectangleF[0].X; rectangleF[0].Y = rectangleF[0].Y; g.DrawRectangles(paint.pen, rectangleF); g.DrawString ( modelSteps[i].Name, paint.Font, paint.brush, rectangleF[0].X, rectangleF[0].Y - (paint.Font.Height) ); break; case Global.Positions.ICam1: rectangleF[0] = modelSteps[i].ForDrawResult(ICam1); rectangleF[0].X = rectangleF[0].X + ICam0.Width; rectangleF[0].Y = rectangleF[0].Y; g.DrawRectangles(paint.pen, rectangleF); g.DrawString ( modelSteps[i].Name, paint.Font, paint.brush, rectangleF[0].X, rectangleF[0].Y - (paint.Font.Height) ); break; case Global.Positions.ICam2: rectangleF[0] = modelSteps[i].ForDrawResult(ICam2); rectangleF[0].X = rectangleF[0].X; rectangleF[0].Y = rectangleF[0].Y + ICam0.Height; g.DrawRectangles(paint.pen, rectangleF); g.DrawString ( modelSteps[i].Name, paint.Font, paint.brush, rectangleF[0].X, rectangleF[0].Y - (paint.Font.Height) ); break; case Global.Positions.ICam3: rectangleF[0] = modelSteps[i].ForDrawResult(ICam3); rectangleF[0].X = rectangleF[0].X + ICam0.Width; rectangleF[0].Y = rectangleF[0].Y + ICam0.Height; g.DrawRectangles(paint.pen, rectangleF); g.DrawString ( modelSteps[i].Name, paint.Font, paint.brush, rectangleF[0].X, rectangleF[0].Y - (paint.Font.Height) ); break; } } } //resultBitmap = resizeImage(resultBitmap, new Size(1920, 1080)); this.ModelImageResult = Global.ICOP_history_path_image + this.ModelName + "_" + dateTime.ToString("HHmmss") + "_" + this.result + ".png"; resultBitmap.Save(ModelImageResult); }
private void pbICam_Paint(object sender, PaintEventArgs e) { if (modelProgram.loaded) { string pictureBoxIcam = ((PictureBox)sender).Name; switch (pictureBoxIcam) { case "pbICam0": for (int i = 0; i < modelProgram.modelSteps.Count; i++) { if (modelProgram.modelSteps[i].Result == Global.ICOP_tester_OK) { paint = paint_OK; } else { paint = paint_NG; } if (modelProgram.modelSteps[i].Position == Global.Positions.ICam0 && modelProgram.modelSteps[i].Skip == false) { RectangleF rectangleF = modelProgram.modelSteps[i].ForDraw(pbICam0); e.Graphics.DrawRectangle(paint.pen, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); e.Graphics.DrawString ( modelProgram.modelSteps[i].Name, paint.Font, paint.brush, modelProgram.modelSteps[i].ForDraw(pbICam0).X, modelProgram.modelSteps[i].ForDraw(pbICam0).Y - (paint.Font.Height) ); } } break; case "pbICam1": for (int i = 0; i < modelProgram.modelSteps.Count; i++) { if (modelProgram.modelSteps[i].Result == Global.ICOP_tester_OK) { paint = paint_OK; } else { paint = paint_NG; } if (modelProgram.modelSteps[i].Position == Global.Positions.ICam1 && modelProgram.modelSteps[i].Skip == false) { RectangleF rectangleF = modelProgram.modelSteps[i].ForDraw(pbICam1); e.Graphics.DrawRectangle(paint.pen, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); e.Graphics.DrawString ( modelProgram.modelSteps[i].Name, paint.Font, paint.brush, modelProgram.modelSteps[i].ForDraw(pbICam1).X, modelProgram.modelSteps[i].ForDraw(pbICam1).Y - (paint.Font.Height) ); } } break; case "pbICam2": for (int i = 0; i < modelProgram.modelSteps.Count; i++) { if (modelProgram.modelSteps[i].Result == Global.ICOP_tester_OK) { paint = paint_OK; } else { paint = paint_NG; } if (modelProgram.modelSteps[i].Position == Global.Positions.ICam2 && modelProgram.modelSteps[i].Skip == false) { RectangleF rectangleF = modelProgram.modelSteps[i].ForDraw(pbICam2); e.Graphics.DrawRectangle(paint.pen, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); e.Graphics.DrawString ( modelProgram.modelSteps[i].Name, paint.Font, paint.brush, modelProgram.modelSteps[i].ForDraw(pbICam2).X, modelProgram.modelSteps[i].ForDraw(pbICam2).Y - (paint.Font.Height) ); } } break; case "pbICam3": for (int i = 0; i < modelProgram.modelSteps.Count; i++) { if (modelProgram.modelSteps[i].Result == Global.ICOP_tester_OK) { paint = paint_OK; } else { paint = paint_NG; } if (modelProgram.modelSteps[i].Position == Global.Positions.ICam3 && modelProgram.modelSteps[i].Skip == false) { RectangleF rectangleF = modelProgram.modelSteps[i].ForDraw(pbICam3); e.Graphics.DrawRectangle(paint.pen, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); e.Graphics.DrawString ( modelProgram.modelSteps[i].Name, paint.Font, paint.brush, modelProgram.modelSteps[i].ForDraw(pbICam3).X, modelProgram.modelSteps[i].ForDraw(pbICam3).Y - (paint.Font.Height) ); } } break; default: break; } } }