CalibrationAuto.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Cognex.VisionPro;
  2. using Cognex.VisionPro.Dimensioning;
  3. using System;
  4. using System.Windows.Controls;
  5. using TeamAAS_VP.ViewModels.Calibration;
  6. namespace TeamAAS_VP.Views.Calibration
  7. {
  8. /// <summary>
  9. /// Interaction logic for CalibrationAuto
  10. /// </summary>
  11. public partial class CalibrationAuto : UserControl
  12. {
  13. CalibrationAutoViewModel VM;
  14. public CalibrationAuto()
  15. {
  16. InitializeComponent();
  17. VM = DataContext as CalibrationAutoViewModel;
  18. VM.PropertyChanged += VM_PropertyChanged;
  19. this.display.VerticalScrollBar = false;
  20. this.display.HorizontalScrollBar = false;
  21. this.display.AutoFit = true;
  22. this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
  23. }
  24. private int _imageWidth;
  25. private int _imageHeight;
  26. private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  27. {
  28. try
  29. {
  30. if (e.PropertyName == "Image")
  31. {
  32. this.display.Image = VM.Image;
  33. //图像中心点坐标
  34. _imageWidth = this.display.Image.Width;
  35. _imageHeight = this.display.Image.Height;
  36. }
  37. else if (e.PropertyName == "Graphic")
  38. {
  39. this.display.StaticGraphics.Clear();
  40. CogGraphicCollection graphic = new CogGraphicCollection();
  41. CogCreateLineTool line1 = new CogCreateLineTool();
  42. CogCreateLineTool line2 = new CogCreateLineTool();
  43. line1.InputImage = this.display.Image;
  44. line2.InputImage = this.display.Image;
  45. line1.Line.X = _imageWidth / 2;
  46. line1.Line.Y = _imageHeight / 2;
  47. line1.Line.Rotation = 0;
  48. line2.Line.X = _imageWidth / 2;
  49. line2.Line.Y = _imageHeight / 2;
  50. line2.Line.Rotation = Math.PI / 180 * 90;
  51. line1.Run();
  52. line2.Run();
  53. graphic.Add(line1.GetOutputLine());
  54. graphic.Add(line2.GetOutputLine());
  55. this.display.StaticGraphics.Clear();
  56. this.display.StaticGraphics.AddList(graphic, "");
  57. if (VM.Graphic!=null)
  58. {
  59. this.display.StaticGraphics.AddList(VM.Graphic, "");
  60. }
  61. }
  62. }
  63. catch (System.Exception)
  64. {
  65. }
  66. }
  67. }
  68. }