TouchImage.cs 1.3 KB

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