TouchImage.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. public TouchImage(int width, int height)
  25. {
  26. image = new Image<Gray, byte>(width, height);
  27. }
  28. public void setStateAt(Point point, TouchImageState state)
  29. {
  30. setStateAt(point.X, point.Y, state);
  31. }
  32. public void setStateAt(int x, int y, TouchImageState state)
  33. {
  34. image.Data[y, x, 0] = (byte)state;
  35. int size = 5;
  36. if (state == TouchImageState.touchTracked || state == TouchImageState.touchDetected)
  37. {
  38. image.Draw(new CircleF(new System.Drawing.PointF(x, y), size), new Gray((byte)state), 0);
  39. }
  40. }
  41. public TouchImageState getStateAt(int x, int y)
  42. {
  43. return (TouchImageState)image.Data[y, x, 0];
  44. }
  45. }
  46. }