ImageAttributes.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // (C) 2002-4 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Drawing;
  11. namespace System.Drawing.Imaging
  12. {
  13. /// <summary>
  14. /// Summary description for ImageAttributes.
  15. /// </summary>
  16. public sealed class ImageAttributes : ICloneable, IDisposable {
  17. private IntPtr nativeImageAttr = IntPtr.Zero;
  18. internal IntPtr NativeObject{
  19. get{
  20. return nativeImageAttr;
  21. }
  22. }
  23. public ImageAttributes() {
  24. Status status = GDIPlus.GdipCreateImageAttributes(out nativeImageAttr);
  25. if (status != Status.Ok)
  26. throw new Exception ("Error calling GDIPlus.GdipCreateImageAttributes:" +status);
  27. Console.WriteLine("ImageAttributes().ImageAttributes()" + nativeImageAttr);
  28. }
  29. //Clears the color keys for all GDI+ objects
  30. public void ClearColorKey(){
  31. Status status = GDIPlus.GdipSetImageAttributesColorKeys(nativeImageAttr, ColorAdjustType.Default, false, 0,0);
  32. if (status != Status.Ok)
  33. throw new Exception ("Error calling GDIPlus.ClearColorKey:" +status);
  34. }
  35. //Sets the color keys for all GDI+ objects
  36. public void SetColorKey(Color colorLow, Color colorHigh){
  37. Status status = GDIPlus.GdipSetImageAttributesColorKeys(nativeImageAttr,
  38. ColorAdjustType.Default, true, colorLow.ToArgb(), colorHigh.ToArgb());
  39. if (status != Status.Ok)
  40. throw new Exception ("Error calling GDIPlus.GdipSetImageAttributesColorKeys:" +status);
  41. }
  42. public void SetColorMatrix(ColorMatrix colorMatrix) {
  43. Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr, ColorAdjustType.Default,
  44. true, colorMatrix, (ColorMatrix)null, ColorMatrixFlag.Default);
  45. if (status != Status.Ok)
  46. throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
  47. }
  48. public void SetColorMatrix(ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag) {
  49. Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr, ColorAdjustType.Default,
  50. true, colorMatrix, (ColorMatrix)null, colorMatrixFlag);
  51. if (status != Status.Ok)
  52. throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
  53. }
  54. public void SetColorMatrix(ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag, ColorAdjustType colorAdjustType) {
  55. Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr,colorAdjustType,
  56. true, colorMatrix, (ColorMatrix)null, colorMatrixFlag);
  57. if (status != Status.Ok)
  58. throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
  59. }
  60. void Dispose (bool disposing)
  61. {
  62. if (!disposing) return;
  63. Status status = GDIPlus.GdipDisposeImageAttributes(nativeImageAttr);
  64. if (status != Status.Ok)
  65. throw new Exception ("Error calling GDIPlus.GdipDisposeImageAttributes:" +status);
  66. else
  67. nativeImageAttr = IntPtr.Zero;
  68. }
  69. public void Dispose() {
  70. Dispose (true);
  71. System.GC.SuppressFinalize (this);
  72. }
  73. ~ImageAttributes() {
  74. Dispose (false);
  75. }
  76. [MonoTODO]
  77. object ICloneable.Clone()
  78. {
  79. throw new NotImplementedException ();
  80. }
  81. }
  82. }