OutputImage.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7. using Emgu.CV;
  8. using Emgu.CV.Structure;
  9. namespace bbiwarg.Graphics
  10. {
  11. class OutputImage
  12. {
  13. public Image<Rgb, byte> Image { get; private set; }
  14. public OutputImage(int width, int height)
  15. {
  16. Image = new Image<Rgb, byte>(width, height);
  17. }
  18. public Color getColotAt(int x, int y) {
  19. byte red = Image.Data[y, x, 0];
  20. byte green = Image.Data[y, x, 1];
  21. byte blue = Image.Data[y, x, 2];
  22. return Color.FromArgb(red,green,blue);
  23. }
  24. public void drawLineSegment(bbiwarg.Utility.LineSegment2D lineSegment, Color color, int thickness = 1)
  25. {
  26. Image.Draw(new LineSegment2D(lineSegment.P1, lineSegment.P2), new Rgb(color), thickness);
  27. }
  28. public void drawContour(Contour<Point> contour, Color color, int thickness = 1)
  29. {
  30. Image.Draw(contour, new Rgb(color), thickness);
  31. }
  32. public void drawPoints(Seq<Point> points, Color color, int thickness = 1)
  33. {
  34. Image.Draw(points, new Rgb(color), thickness);
  35. }
  36. public void drawPixel(int x, int y, Color color)
  37. {
  38. Image.Data[y, x, 0] = color.R;
  39. Image.Data[y, x, 1] = color.G;
  40. Image.Data[y, x, 2] = color.B;
  41. }
  42. public void fillCircle(int x, int y, float radius, Color color)
  43. {
  44. Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(color), 0);
  45. }
  46. public void drawRectangle(int x, int y, int width, int height, byte r, byte g, byte b, int thichness = 0)
  47. {
  48. Image.Draw(new Rectangle(x, y, width, height), new Rgb(r, g, b), thichness);
  49. }
  50. }
  51. }