ImageAttributes.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // System.Drawing.Imaging.ImageAttributes.cs
  3. //
  4. // Author:
  5. // Dennis Hayes ([email protected]) (stubbed out)
  6. // Jordi Mas i Hernàndez ([email protected])
  7. // Sanjay Gupta ([email protected])
  8. //
  9. // (C) 2002-4 Ximian, Inc. http://www.ximian.com
  10. //
  11. using System;
  12. using System.Drawing;
  13. namespace System.Drawing.Imaging
  14. {
  15. /// <summary>
  16. /// Summary description for ImageAttributes.
  17. /// </summary>
  18. public sealed class ImageAttributes : ICloneable, IDisposable {
  19. private IntPtr nativeImageAttr = IntPtr.Zero;
  20. internal IntPtr NativeObject{
  21. get{
  22. return nativeImageAttr;
  23. }
  24. }
  25. public ImageAttributes() {
  26. Status status = GDIPlus.GdipCreateImageAttributes(out nativeImageAttr);
  27. if (status != Status.Ok)
  28. throw new Exception ("Error calling GDIPlus.GdipCreateImageAttributes:" +status);
  29. Console.WriteLine("ImageAttributes().ImageAttributes()" + nativeImageAttr);
  30. }
  31. public void ClearBrushRemapTable()
  32. {
  33. ClearRemapTable (ColorAdjustType.Brush);
  34. }
  35. //Clears the color keys for all GDI+ objects
  36. public void ClearColorKey()
  37. {
  38. ClearColorKey (ColorAdjustType.Default);
  39. }
  40. public void ClearColorKey(ColorAdjustType type)
  41. {
  42. Status status = GDIPlus.GdipSetImageAttributesColorKeys (nativeImageAttr,
  43. type, false, 0, 0);
  44. GDIPlus.CheckStatus (status);
  45. }
  46. public void ClearColorMatrix()
  47. {
  48. ClearColorMatrix (ColorAdjustType.Default);
  49. }
  50. public void ClearColorMatrix(ColorAdjustType type)
  51. {
  52. Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
  53. type, false, null, null, ColorMatrixFlag.Default);
  54. GDIPlus.CheckStatus (status);
  55. }
  56. public void ClearGamma()
  57. {
  58. ClearGamma (ColorAdjustType.Default);
  59. }
  60. public void ClearGamma(ColorAdjustType type)
  61. {
  62. Status status = GDIPlus.GdipSetImageAttributesGamma (nativeImageAttr,
  63. type, false, 0);
  64. GDIPlus.CheckStatus (status);
  65. }
  66. public void ClearNoOp()
  67. {
  68. ClearNoOp (ColorAdjustType.Default);
  69. }
  70. public void ClearNoOp(ColorAdjustType type)
  71. {
  72. Status status = GDIPlus.GdipSetImageAttributesNoOp (nativeImageAttr,
  73. type, false);
  74. GDIPlus.CheckStatus (status);
  75. }
  76. public void ClearOutputChannel()
  77. {
  78. ClearOutputChannel (ColorAdjustType.Default);
  79. }
  80. public void ClearOutputChannel(ColorAdjustType type)
  81. {
  82. Status status = GDIPlus.GdipSetImageAttributesOutputChannel (nativeImageAttr,
  83. type, false, ColorChannelFlag.ColorChannelLast );
  84. GDIPlus.CheckStatus (status);
  85. }
  86. public void ClearOutputChannelColorProfile()
  87. {
  88. ClearOutputChannelColorProfile (ColorAdjustType.Default);
  89. }
  90. public void ClearOutputChannelColorProfile(ColorAdjustType type)
  91. {
  92. Status status = GDIPlus.GdipSetImageAttributesOutputChannelColorProfile (nativeImageAttr,
  93. type, false, null);
  94. GDIPlus.CheckStatus (status);
  95. }
  96. public void ClearRemapTable()
  97. {
  98. ClearRemapTable (ColorAdjustType.Default);
  99. }
  100. public void ClearRemapTable(ColorAdjustType type)
  101. {
  102. Status status = GDIPlus.GdipSetImageAttributesRemapTable (nativeImageAttr,
  103. type, false, 0, IntPtr.Zero);
  104. GDIPlus.CheckStatus (status);
  105. }
  106. public void ClearThreshold()
  107. {
  108. ClearThreshold (ColorAdjustType.Default);
  109. }
  110. public void ClearThreshold(ColorAdjustType type)
  111. {
  112. Status status = GDIPlus.GdipSetImageAttributesThreshold (nativeImageAttr,
  113. type, false, 0);
  114. GDIPlus.CheckStatus (status);
  115. }
  116. //Sets the color keys for all GDI+ objects
  117. public void SetColorKey(Color colorLow, Color colorHigh)
  118. {
  119. Status status = GDIPlus.GdipSetImageAttributesColorKeys(nativeImageAttr,
  120. ColorAdjustType.Default, true, colorLow.ToArgb(), colorHigh.ToArgb());
  121. if (status != Status.Ok)
  122. throw new Exception ("Error calling GDIPlus.GdipSetImageAttributesColorKeys:" +status);
  123. }
  124. public void SetColorMatrix(ColorMatrix colorMatrix) {
  125. Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr, ColorAdjustType.Default,
  126. true, colorMatrix, (ColorMatrix)null, ColorMatrixFlag.Default);
  127. if (status != Status.Ok)
  128. throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
  129. }
  130. public void SetColorMatrix(ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag) {
  131. Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr, ColorAdjustType.Default,
  132. true, colorMatrix, (ColorMatrix)null, colorMatrixFlag);
  133. if (status != Status.Ok)
  134. throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
  135. }
  136. public void SetColorMatrix(ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag, ColorAdjustType colorAdjustType) {
  137. Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr,colorAdjustType,
  138. true, colorMatrix, (ColorMatrix)null, colorMatrixFlag);
  139. if (status != Status.Ok)
  140. throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
  141. }
  142. void Dispose (bool disposing)
  143. {
  144. if (!disposing) return;
  145. Status status = GDIPlus.GdipDisposeImageAttributes(nativeImageAttr);
  146. if (status != Status.Ok)
  147. throw new Exception ("Error calling GDIPlus.GdipDisposeImageAttributes:" +status);
  148. else
  149. nativeImageAttr = IntPtr.Zero;
  150. }
  151. public void Dispose() {
  152. Dispose (true);
  153. System.GC.SuppressFinalize (this);
  154. }
  155. ~ImageAttributes() {
  156. Dispose (false);
  157. }
  158. [MonoTODO]
  159. object ICloneable.Clone()
  160. {
  161. throw new NotImplementedException ();
  162. }
  163. }
  164. }