TouchImage.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Emgu.CV;
  8. using Emgu.CV.Structure;
  9. using bbiwarg.Utility;
  10. namespace bbiwarg.Images
  11. {
  12. public enum TouchImageState
  13. {
  14. none = 0,
  15. touchArea = 1,
  16. touchAreaMatched = 2,
  17. touchAreaStatusBar = 3,
  18. touchDetected = 4,
  19. touchTracked = 5
  20. }
  21. class TouchImage
  22. {
  23. private Image<Gray, byte> image;
  24. private List<Vector2D> oldTouches;
  25. public TouchImage(int width, int height)
  26. {
  27. image = new Image<Gray, byte>(width, height);
  28. oldTouches = new List<Vector2D>();
  29. }
  30. public void setStateAt(Point point, TouchImageState state) {
  31. setStateAt(point.X, point.Y, state);
  32. }
  33. public void setStateAt(int x, int y, TouchImageState state)
  34. {
  35. image.Data[y, x, 0] = (byte)state;
  36. int size = 5;
  37. if (state == TouchImageState.touchTracked || state == TouchImageState.touchDetected)
  38. {
  39. image.Draw(new CircleF(new System.Drawing.PointF(x, y), size), new Gray((byte) state), 0);
  40. }
  41. }
  42. public TouchImageState getStateAt(int x, int y)
  43. {
  44. return (TouchImageState)image.Data[y, x, 0];
  45. }
  46. }
  47. }