Field.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. namespace OTSCommon.DBOperate.Model
  6. {
  7. [Serializable]
  8. public class Field
  9. {
  10. Bitmap mImage = null;
  11. /// <summary>
  12. /// FieldID
  13. /// </summary>
  14. public int FieldID
  15. {
  16. get;
  17. set;
  18. }
  19. /// <summary>
  20. /// FieldPosX
  21. /// </summary>
  22. public int FieldPosX
  23. {
  24. get;
  25. set;
  26. }
  27. /// <summary>
  28. /// FieldPosY
  29. /// </summary>
  30. public int FieldPosY
  31. {
  32. get;
  33. set;
  34. }
  35. public PointF GetOTSPosition()
  36. {
  37. return new PointF(FieldPosX, FieldPosY);
  38. }
  39. public Bitmap GetFieldImage()
  40. {
  41. if (mImage == null)
  42. {
  43. //mImage = DrawFunction.ReadImageFile(FieldImageName);
  44. if (!File.Exists(FieldImageName))
  45. {
  46. return null;//文件不存在
  47. }
  48. FileStream fs = File.OpenRead(FieldImageName); //OpenRead
  49. int filelength = 0;
  50. filelength = (int)fs.Length; //获得文件长度
  51. Byte[] image = new Byte[filelength]; //建立一个字节数组
  52. fs.Read(image, 0, filelength); //按字节流读取
  53. System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
  54. fs.Close();
  55. mImage = new Bitmap(result);
  56. }
  57. return mImage;
  58. }
  59. /// <summary>
  60. /// FieldPosY
  61. /// </summary>
  62. public string FieldImageName
  63. {
  64. get;
  65. set;
  66. }
  67. /// <summary>
  68. /// ParticleList
  69. /// </summary>
  70. public List<Particle> ParticleList
  71. {
  72. get;
  73. set;
  74. }
  75. }
  76. }