BitmapData.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Veldrid.Common
  9. {
  10. public class BitmapData:IDisposable
  11. {
  12. public static BitmapData Empty = new BitmapData();
  13. public Vector2 Size { get; }
  14. public BitmapData()
  15. {
  16. Width= 0;
  17. Height= 0;
  18. Data = new Byte[0];
  19. Size = Vector2.Zero;
  20. }
  21. public BitmapData(int width,int height, byte[] data)
  22. {
  23. this.Width = width;
  24. this.Height= height;
  25. this.Data = data;
  26. Size= new Vector2(width,height);
  27. }
  28. private bool disposedValue;
  29. public int Width { get; private set; }
  30. public int Height { get; private set; }
  31. public Byte[] Data { get; private set; }
  32. public static Boolean operator !=(BitmapData a, BitmapData b)
  33. {
  34. return !a.Equals(b);
  35. }
  36. public static Boolean operator ==(BitmapData a, BitmapData b)
  37. {
  38. return a.Equals(b);
  39. }
  40. public override bool Equals([NotNullWhen(true)] object? obj)
  41. {
  42. if (obj is BitmapData bitmap)
  43. {
  44. bool result = Width == bitmap.Width && Height == bitmap.Height;
  45. if (result)
  46. {
  47. if (Data == null || Data.Length == 0 || Data.Length != bitmap.Data.Length)
  48. {
  49. return false;
  50. }
  51. else
  52. {
  53. for (int i = 0; i < Data.Length; i++)
  54. {
  55. if (Data[i] != bitmap.Data[i]) return false;
  56. }
  57. return true;
  58. }
  59. }
  60. else
  61. {
  62. return false;
  63. }
  64. }
  65. else
  66. {
  67. return false;
  68. }
  69. }
  70. public override int GetHashCode()
  71. {
  72. return base.GetHashCode();
  73. }
  74. protected virtual void Dispose(bool disposing)
  75. {
  76. if (!disposedValue)
  77. {
  78. if (disposing)
  79. {
  80. // TODO: 释放托管状态(托管对象)
  81. }
  82. // TODO: 释放未托管的资源(未托管的对象)并重写终结器
  83. // TODO: 将大型字段设置为 null
  84. disposedValue = true;
  85. }
  86. }
  87. // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器
  88. // ~BitmapData()
  89. // {
  90. // // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
  91. // Dispose(disposing: false);
  92. // }
  93. public void Dispose()
  94. {
  95. // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
  96. Dispose(disposing: true);
  97. GC.SuppressFinalize(this);
  98. }
  99. }
  100. }